ReactJS-net::ERR_FILE_NOT_FOUND
ReactJS - net::ERR_FILE_NOT_FOUND
我的 React 应用程序的生产版本突然出现问题。它们在开发中运行良好,但是当我构建它们时,出现控制台错误:
/static/css/main.f6418f8a.chunk.css:1 加载资源失败:
net::ERR_FILE_NOT_FOUND
1.13eeb203.chunk.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
main.1e6014ca.chunk.js:1 Failed to load resource:
net::ERR_FILE_NOT_FOUND
/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
在执行以下命令后收到此错误:
create-react-app whatiswrong
npm run build
然后在我的浏览器中打开 index.html,就像打开我构建的任何其他 React 应用程序一样。
你 运行 你的应用怎么样?您只是在浏览器中打开 index.html 还是使用 serve -s build
之类的?
如果您是通过第一个选项进行操作,那么您应该考虑尝试 serve -s build
您需要将 "homepage": "./"
添加到您的 package.json。
来自:
https://github.com/facebook/create-react-app/issues/6275#issuecomment-457813277
- 打开您的 package.json 文件。
- 将此条目添加到其中
"homepage":"path\to\your\project\build\"
- 重新运行命令
npm run build
.
The issue here was when you run the npm run build command without the homepage entry added in your package.json,it is built assuming that the project directory (where you are running the command) is hosted at server root.
screen-shot commandline
D:\git_repo\my-app>npm run build
> my-app@0.1.0 build D:\git_repo\my-app
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
44.57 KB build\static\js\main.8a29685f.js
**The project was built assuming it is hosted at root directory.
You can control this with the homepage field in your package.json.**
The build folder is ready to be deployed.
D:\git_repo\my-app>
我的 React 应用程序的生产版本突然出现问题。它们在开发中运行良好,但是当我构建它们时,出现控制台错误:
/static/css/main.f6418f8a.chunk.css:1 加载资源失败:
net::ERR_FILE_NOT_FOUND
1.13eeb203.chunk.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
main.1e6014ca.chunk.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
在执行以下命令后收到此错误:
create-react-app whatiswrong
npm run build
然后在我的浏览器中打开 index.html,就像打开我构建的任何其他 React 应用程序一样。
你 运行 你的应用怎么样?您只是在浏览器中打开 index.html 还是使用 serve -s build
之类的?
如果您是通过第一个选项进行操作,那么您应该考虑尝试 serve -s build
您需要将 "homepage": "./"
添加到您的 package.json。
来自: https://github.com/facebook/create-react-app/issues/6275#issuecomment-457813277
- 打开您的 package.json 文件。
- 将此条目添加到其中
"homepage":"path\to\your\project\build\"
- 重新运行命令
npm run build
.
The issue here was when you run the npm run build command without the homepage entry added in your package.json,it is built assuming that the project directory (where you are running the command) is hosted at server root.
screen-shot commandline
D:\git_repo\my-app>npm run build
> my-app@0.1.0 build D:\git_repo\my-app
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
44.57 KB build\static\js\main.8a29685f.js
**The project was built assuming it is hosted at root directory.
You can control this with the homepage field in your package.json.**
The build folder is ready to be deployed.
D:\git_repo\my-app>