'Push rejected, failed to compile Node.js app heroku

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 2 threads.
Compressing objects: 100% (862/862), done.
Writing objects: 100% (975/975), 3.74 MiB | 80.00 KiB/s, done.
Total 975 (delta 70), reused 0 (delta 0)

-----> Node.js app detected
-----> Resolving engine versions
   Using Node.js version: 0.10.15
   Using npm version: 1.3.3
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
   npm ERR! install Couldn't read dependencies
!     Push rejected, failed to compile Node.js app

To [email protected]:hidden-reaches-9268.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:hidden-reaches-9268.git'

And this is my package.json:

{
  "name": "fnBoard",
  "version": "0.0.1",
  "private": true,
  "scripts": {
  "start": "node server.js"
},

  "dependencies": {
   "socket.io": "0.9.x"
},
   "engines": {
     "node": "0.10.x",
     "npm": "1.3.x"
   }
}

There's a bunch of error inside and I have no idea why this happen. please help. -thanks



Solution 1:[1]

The easiest way to make this work is to add node_modules to your .gitignore. Lots more info here: Fail to deploy node.js application to heroku

Solution 2:[2]

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.

enter image description here

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

Solution 3:[3]

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.

Solution 4:[4]

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.

Solution 5:[5]

I solved this.
I got the same error:

"Push rejected, failed to compile Node.js app"

but my log was complaining about this Unknown option:

'--target'

I solved this digging out on my package.json and I found this line of code below:

"postinstall": "ng build --aot --target=production"

I removed the --target=production.

On my terminal:
I commited again $ git commit -m 'anything here'
then $ git push heroku master
And done.

Solution 6:[6]

  1. git rm package-lock.json
  2. npm init -y
  3. npm install
  4. git add .
  5. git commit -m "changes"
  6. git push heroku main

Solution 7:[7]

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.

Solution 8:[8]

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.

Solution 9:[9]

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

Solution 10:[10]

I fixed this by just removing the package lock.json and then again git add . and git commit after removing the lock file.

Solution 11:[11]

I was getting this error when pushing a Frontity app to Heroku. I also couldn't get the app to compile on my machine locally even after clearing my npm cache, deleting node_modules, etc..

What worked for me was using this Node version manager to change my local Node version from 18.0.0 to 16.10.0.

sudo n 16.10.0

Then updating the Node version in package.json to the same version:

"engines": {
  "node": "16.10.0",
  "npm": ">=6.0.0"
},