When I tried to push my nodejs app to heroku with git push heroku master
, i got this:
Counting objects: 975, done.
Delta compression using up to
I am working in ReactJS and I am trying to deploy my project on Heroku server. At that time I have found same error like this:
Push rejected, failed to compile Node.js app.
Solution is:
If you use yarn:
git rm yarn.lock
git push heroku master
If you use npm:
git rm package-lock.json
git push heroku master
Adding node_modules may be easy but not the correct approach here. Instead do git push -f heroku master
in order to FORCE push your updates telling heroku to overwrite any pre-existing node_modules. This way your git repo is not bogged down with node libs.
Issue When you use Yarn to install node modules, it generates a yarn.lock file which contains a list of the exact modules that it installed when you ran the command. If the dependencies in package.json change, but a new yarn.lock file is not generated by the Yarn executable we fail the build to prevent subtle bugs and security issues that could affect your application at runtime.
Resolution This issue commonly occurs when your application uses Yarn but some other tool modifies the package.json file without invoking yarn install. An example would be using npm to install a new module instead of Yarn, or manually updating a version requirement by hand.
To resolve this, run yarn install and check in the updated yarn.lock file.
ensure you have removed package.lock file and commited the same before push.
I fixed it by join
to the path of an imported module that did not belong to Node. More info here
https://stackoverflow.com/a/64772154/12982656
Try setting a heroku-postbuild script to your package.json and make sure to include your engines.
"scripts": {
"heroku-postbuild": "npm run build"
},
"engines": {
"npm": "5.6.0",
"node": "8.10.0"
}
I would try and avoid force pushing anything at all costs whether it be to github or heroku.
I had the same issue , the problem was with git add. I had forgotten to add the node_modules files. I closed the terminal and ran the set of commands given in the Getting started with Heroku and NodeJs[1] again. The application was successfully pushed onto the stack.