Hey,
When I try to serve my production build app from localhost (here 8014) I just get a blank page. In the console i get the error message: GET localhost:8014/static/js/2.2612b9d... net::ERR_ABORTED 404 (Not Found)
Any idea?
the express server doesn't know how to host the static files generated by created webpack.
put app.use(express.static('build')) to tell express where to look for them.
@Lou maybe this should be included in the article.
Re-thinking developer experience • Product @Gitpod 🍊 Helping folks get their start in cloud • @openupthecloud ☁️ AWS Community Builder 🛠 Replies in GIFS 😃
But depending on how you're referencing the build folder it may depend on where you're the server start commands from. Try as @jaspersurmont
to ensure that you're correctly pointing to the build folder, and that it has at the least an index.html inside.
I did fix it, however I'm not so sure what exactly I did.
I think that one of the issues was that I didn't refer to the build folder correctly. Try messing around with that a bit
leaving this here for anyone that might be encountering the same issue! Here's how I fixed it, I just needed to add a route that matches any (*) that don't match exactly '/', and serve the react app:
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Handles any requests that don't match the ones above
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
Hey,
When I try to serve my production build app from localhost (here 8014) I just get a blank page. In the console i get the error message: GET localhost:8014/static/js/2.2612b9d... net::ERR_ABORTED 404 (Not Found)
Any idea?
the express server doesn't know how to host the static files generated by created webpack.
put
app.use(express.static('build'))
to tell express where to look for them.@Lou maybe this should be included in the article.
Thanks @bordenjardine . The post does currently refer to the build folder:
app.use(express.static(path.join(__dirname, 'build')));
But depending on how you're referencing the build folder it may depend on where you're the server start commands from. Try as @jaspersurmont to ensure that you're correctly pointing to the build folder, and that it has at the least an index.html inside.
did you find a solution for this? i having the same problem.
I did fix it, however I'm not so sure what exactly I did.
I think that one of the issues was that I didn't refer to the build folder correctly. Try messing around with that a bit
leaving this here for anyone that might be encountering the same issue! Here's how I fixed it, I just needed to add a route that matches any (*) that don't match exactly '/', and serve the react app:
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Handles any requests that don't match the ones above
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
Cheers!
(*) did the trick for me too :)