1

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"));
 });

1 Answer 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.

Sign up to request clarification or add additional context in comments.

4 Comments

I already did that, same thing happened.
try join instead of resolve
Thank you so much. It solved my problem. Can you please explain why one worked and other didn't? Thanks.
resolve treats the first argument as the root of your directory. join just concatenates the arguments, then creates a string from them. stackoverflow.com/questions/35048686/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.