D
D
Demigodd2019-09-25 09:01:56
Heroku
Demigodd, 2019-09-25 09:01:56

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.
2XeZq.png
The files seem to be connected correctly.
2XeZr.png
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'));
  });
}

the paths in my applications look like this.
/APP
-/build
-/public
-/src
--/client
--/server
--app.ts
--server.ts
-package.json
Well, package.json itself
// package.json

"homepage": ".",
"scripts": {
  "start:react": "react-scripts start",
  "start": "node --require ./ts-hook.js ./src/server.ts",
  "heroku-postbuild": "react-scripts build"
},

What could be the problem ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-09-25
@Demigodd

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 question

Ask a Question

731 491 924 answers to any question