Answer the question
In order to leave comments, you need to log in
Why does Response return "You need to enable JavaScript to run this app." when deploying React+Express+Heroku?
After deploying the application, everything ended successfully, but when sending a request, for example, getting user data, the message " You need to enable JavaScript to run this app. " is returned.
The files seem to be connected correctly.
This is how I return a built React App built via react-scripts build from the server.
// server
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, '../build')));
app.get('*', (req: any, res: any) => {
res.sendFile(path.resolve(__dirname, '../build', 'index.html'));
});
}
// package.json
"homepage": ".",
"scripts": {
"start:react": "react-scripts start",
"start": "node --require ./ts-hook.js ./src/server.ts",
"heroku-postbuild": "react-scripts build"
},
Answer the question
In order to leave comments, you need to log in
only on Heroku?
it looks like the router in the express is not connected, and instead of requests to the API it gives react app,
somewhere there should be
app.use('/api/', require('./routes'))
before app.get('*' , ...build/index.html..)
maybe this piece of code was left out of the process.env.NODE_ENV === 'production' check?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question