webpack 无法加载资源:服务器在部署的React.js项目中响应状态为404(未找到)

drnojrws  于 12个月前  发布在  Webpack
关注(0)|答案(2)|浏览(192)

当我将react项目部署到Surge中时,构建是成功的,并且可以获得应用URL。但是当我链接到URL时,我可以在inspect控制台中看到一个空白页面和一些错误:

Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found) manifest.json:1
Manifest: Line: 1, column: 1, Syntax error. manifest.json:1 
Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.css:1

字符串
下面是我的package.json文件中的react启动脚本。

"scripts": {
  "build": "REACT_APP_BACKEND=true PUBLIC_URL='/sing-app-react' node scripts/build.js",
  "start": "node scripts/start.js",
  "start:backend": "REACT_APP_BACKEND=true node scripts/start.js",
  "test": "node scripts/test.js"
},


以及导致错误https://lopsided-dinner.surge.sh/sing-app-react/static/css/3.138a0231.chunk.css的css文件的链接地址。

des4xlb0

des4xlb01#

第一个月
这个网站的网址由React脚本应该是类似https://your domain/static/css...
删除构建脚本中的PUBLIC_URL并再次运行构建。
它将构建源代码引导到/static/....
希望这对你有意义!

v2g6jxz6

v2g6jxz62#

在我的例子中,问题是我从build文件夹中提供我的react项目,而.gitignore文件中有/build。我从.gitignore文件中删除了/build,它工作了。

相关问题