stylesuxx / generator-react-webpack-redux

React Webpack Generator including Redux support
Other
552 stars 85 forks source link

I get a 'Failed to load resource: net::ERR_FILE_NOT_FOUND' in index.html dist folder #66

Closed codestitch closed 7 years ago

codestitch commented 7 years ago

After doing npm run dist and then opening index.html in dist folder I got the error 'Failed to load resource: net::ERR_FILE_NOT_FOUND'.

project url: https://github.com/codestitch/dashboard-material

i check on the network (inspect element) and i guess it didn't find app.js.

Please help me w/ the issue.

Thank you

codestitch commented 7 years ago

I also tried to create a new project and use the generator. After that I run npm run dist and open index.html at dist folder and got the same issue.

Is there anything I would do before running dist?

Thank you.

stylesuxx commented 7 years ago

Are you serving the file properly, or just accessing it via file browser?

you can serve your dist files by running npm run serve:dist

If you want to serve your app from github you can do this by using the gh-pages branch and deploying the content of your dist directory there.

I did it here the exact same way with a project of mine. This is what the gh-pages branch should look like, and the result on stylesuxx.github.io/LiftOff-Track-and-Race-Generator.

codestitch commented 7 years ago

Hi sir @stylesuxx. Thank you for responding to my issue. I am newbie reactjs, redux and setup.

Yes, after running npm run dist I open the file (index.html) via browser (chrome) and got this result:

screen shot 2017-02-10 at 9 50 40 pm

and also in my public server:

screen shot 2017-02-10 at 9 57 01 pm

I was thinking that when you run npm run dist your project will be compiled and minified and then you can run it on browser or put it in the server and then run it (like in my public server) like what is stated in yeoman website.

stylesuxx commented 7 years ago

If you are not serving from the top level (you are in a folder), you need to adjust the path to app.js in index.html

Change this line: <script type="text/javascript" src="/assets/app.js"></script>

to this: <script type="text/javascript" src="./assets/app.js"></script>

this way it will import relative to your index.html

Do the same with the path to the favicon.

codestitch commented 7 years ago

I changed it to <script type="text/javascript" src="./assets/app.js"></script>

screen shot 2017-02-10 at 10 29 07 pm

but still got a blank page.

I should be seeing this.

screen shot 2017-02-10 at 10 30 13 pm
stylesuxx commented 7 years ago

I just cloned your repo, adjusted the path, ran npm run dist npm run serve:dist

Also tried serving it with python one liner (from within the dist folder): python -m SimpleHTTPServer 12345

and it is behaving as expected.

screenshot from 2017-02-10 16-00-10

Might be an issue with the router when the app is not properly served. You are only accessing it via file browser and not serving it.

codestitch commented 7 years ago

What do you suggest sir to do? I'm bit confused because when I debug the app via npm run serve it works fine.

stylesuxx commented 7 years ago

Well, like I said before, simply serve it any way you want and you should be OK. I do not know your setup, but I provided a solution to serve it with python. As long as your path is correct you should be able to serve it with any http server...

codestitch commented 7 years ago

Hello sir.

I tried to create a fresh new react-webpack-redux project and there something I notice with routing w/c I don't have idea how to solve.

First scenario: Without Router Compilation. Compiled using npm run dist. Copied the files from dist folder and placed in my htdocs in my public server (using xampp).

test1

works fine. Also works fine in my local Drive C:

test2

Now when I use React-Router (I followed in your wiki - added IndexRoute).

test6

It worked on localhost:8000 w/ the command npm run serve. It worked on localhost:8000 w/ the command npm run serve.

test3

Now when I compile to production. npm run dist and then same thing copy the files from /dist folder and place in my public server (same as the first scenario) inside htdocs folder.

test5

It won't run. Same in my local drive.

test4

Am I missing something when using Routes? Or do i need to configure something in my public server (I'm using xampp).

I hope you can help me on this.

Thank you.

codestitch commented 7 years ago

Hi. I was able to fix the problem by using

const browserHistory = useBasename(createHistory)({ basename: "/myapp" });

Though I'm still having problems with browserHistory.push('/') or browserHistory.push('/myapp'), because it is not redirecting to home page after login.

Anyway, thank you. The problem for this issue is fixed.

mr-palindrome commented 4 years ago

Hii, I'm also getting the same problem!! Please help me out... The image bg.png is not visible!! Showing the same error "Failed to load resource: net::ERR_FILE_NOT_FOUND". gt2 git

Mahmoud-farargy commented 4 years ago

I have the same problem, I followed tutorials and step by step guides but it still doesn't work with me. Please help!!