Answer the question
In order to leave comments, you need to log in
Express js fails React build?
Build React project (create-react-app) via yarn build. The assembly can be started via serve -s build (works correctly)
On the express server, I registered
app.use(express.static(path.join(__dirname + "../../client/build")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "..", "..", "client", "build", "index.html"));
});
Answer the question
In order to leave comments, you need to log in
It helped, replaced the above code with this
const root = require('path').join(__dirname, '..', '..', 'client', 'build')
app.use(express.static(root));
app.get("*", (req, res) => {
res.sendFile('index.html', { root });
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question