将React应用程序部署到github页面。 GET ... net :: ERR_ABORTED

时间:2017-12-20 07:23:26

标签: node.js reactjs github-pages

GitHub:https://github.com/Justin-Schneider/portfolio

链接到页面:https://justin-schneider.github.io/portfolio/

链接没有提起任何内容,我得到以下两个错误:

GET https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/css/main.233e2870.css net::ERR_ABORTED
GET https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/js/main.c60b5716.js net::ERR_ABORTED

npm run deploy正确执行

的package.json

{
"name": "my-website",
"version": "0.1.0",
"private": true,
"homepage": "justin-schneider.github.io/portfolio",
"dependencies": {
  "react": "^16.2.0",
  "react-bootstrap": "^0.31.5",
  "react-dom": "^16.2.0",
  "react-scripts": "1.0.17"
},
"scripts": {
  "deploy" : "npm run build&&gh-pages -d build",
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
},
"devDependencies": {
  "gh-pages": "^1.1.0"
}
}

4 个答案:

答案 0 :(得分:1)

"homepage": "."

这行得通!

正如@Maksim Luzik 在上面描述的那样。

我们需要将 package.json 中的 URL 替换为“.”为路径。

例如:- 这..

<块引用>

https://{username}.github.io/portfolio/justinschneider.github.io/portfolio/static/css/main.233e2870.css

将...

<块引用>

./justinschneider.github.io/portfolio/static/css/main.233e2870.css

希望你能明白。

答案 1 :(得分:0)

在您的nodejs中

确保您将构建文件夹设置为静态,以便可以从浏览器访问

   app.use(express.static('./client/build/'));
   app.use('/', express.static('./client/build/index.html'));

答案 2 :(得分:0)

似乎您的react-scripts build反应正在构建相对路径,因此错误地引用https://justin-schneider.github.io/portfolio/justin-schneider.github.io/portfolio/static/css/main.233e2870.css而不是正确的网址:https://justin-schneider.github.io/portfolio/static/css/main.233e2870.css。如果你不能在react-build中改变css和js的dist路径,你可以考虑使用https://webpack.js.org/作为css和js bundler,在那里你可以设置你的静态目录选项。可以正确引用它们。

答案 3 :(得分:0)

在我的package.json中,我需要“https://justin-schneider.github.io/portfolio”,而不仅仅是“justin-schneider.github.io/portfolio”

我更新的package.json

{
"name": "my-website",
"version": "0.1.0",
"private": true,
"homepage": "https://justin-schneider.github.io/portfolio",
"dependencies": {
  "react": "^16.2.0",
  "react-bootstrap": "^0.31.5",
  "react-dom": "^16.2.0",
  "react-scripts": "1.0.17"
 },
"scripts": {
  "deploy" : "npm run build&&gh-pages -d build",
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
  },
"devDependencies": {
  "gh-pages": "^1.1.0"
}
}