Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS - net::ERR_FILE_NOT_FOUND

I'm suddenly having issues with production versions of my react apps. They work fine in development, however when I build them, I get a console error:

/static/css/main.f6418f8a.chunk.css:1 Failed to load resource:

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

This error was received after the following commands:

create-react-app whatiswrong

npm run build

Then open the index.html in my browser like I would for any other react apps I've built.

like image 588
coeu5a Avatar asked Feb 08 '19 11:02

coeu5a


2 Answers

You need to add "homepage": "./" to your package.json.

From: https://github.com/facebook/create-react-app/issues/6275#issuecomment-457813277

like image 117
İbrahim Koray Aksoy Avatar answered Sep 24 '22 03:09

İbrahim Koray Aksoy


  1. Open your package.json file.
  2. Add this entry to it "homepage":"path\to\your\project\build\"
  3. Re-run the command 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

> [email protected] 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>
like image 35
Bhakti Vora Avatar answered Sep 23 '22 03:09

Bhakti Vora