'Problem serving index.html from Express server, but not when I run client separately
I have an app that is made using ReactJS and ExpressJS. The Express server is responsible for getting data, and ReactJS for displaying it. When I run them separately, meaning, I go into the root folder and start the server, and then go into client and start the React app, everything works fine, but when I try to serve the static index.html file I get an error.
Uncaught TypeError: Cannot read properties of undefined (reading 'regular')
This is how I'm serving the static file:
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client". "build", "index.html"));
});
Solution 1:[1]
If your file structure is:
|root
|client
|build
-server.js
then you need to specify the path as __dirname, "client", "build", "index.html" and use join instead of resolve.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
