I'm trying to push a MERN stack app to Heroku for the first time. Express serves the React app successfully when I run the production build on my local machine. Please let me know if you have any suggestions.
Per the Heroku Node.js troubleshooter I...
Specified node and npm versions in package.json
"type": "module",
"version": "1.0.0",
"engines": {
"node": "16.x",
"npm": "8.x"
},
Specified the buildpack.
$ heroku buildpacks
=== my-app Buildpack URL
heroku/nodejs
The relevant portion of the logs appears to be:
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve './views/Home' in '/tmp/build_b656807b/frontend/src'
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
Here are the scripts in package.json
"scripts": {
"client": "npm start --prefix frontend",
"start": "node backend/server",
"server": "nodemon backend/server",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
}
CodePudding user response:
This was resolved by...
Deleting the
Home
component and re-creating it with a different name.Removing the
PORT
variable from.env
.Setting the Express listener to look for the Heroku port by default, and to failover to the dev port.
const PORT = process.env.PORT || 6060