javascript - 加载资源失败 : the server responded with a status of 404 (Not Found) in React. js 项目已部署

标签 javascript reactjs webpack

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

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 文件的链接地址

最佳答案

https://lopsided-dinner.surge.sh/sing-app-react/static/css/3.138a0231.chunk.css
这个由 react 脚本构建的网站 url 应该是 https://your domain/static/css...
删除构建脚本中的 PUBLIC_URL 并再次运行构建。

它将构建源引导到/static/....

希望这对你有意义!

关于javascript - 加载资源失败 : the server responded with a status of 404 (Not Found) in React. js 项目已部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271280/

相关文章:

javascript - 从 Backbone Js View 取消绑定(bind)事件,而不影响 DOM

javascript - 如何将 const reactjs 组件转换为基于类的

javascript - 如何使用 webpack 将文件复制到分发文件夹?

javascript - Webpack 条目的不同名称

webpack - 'import' 和 'export' 可能只出现在顶层

javascript - 如何为每个 jquery 同级创建添加/子值的单击事件

javascript - 制作一个带有 3 个参数的函数范围,有异常(exception)吗?

javascript - jquery 简单的点击事件

javascript - 如何在 JSX 的三元运算符中调用两个函数?

reactjs - 使用 Flux 进行乐观更新(异步)