23

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 git@heroku.com:hidden-reaches-9268.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com: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

Pixeladed
  • 1,773
  • 5
  • 14
  • 26

13 Answers13

25

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

Yogesh Borad
  • 4,287
  • 1
  • 18
  • 17
13

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

Community
  • 1
  • 1
Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
7

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.

gitjason
  • 71
  • 1
  • 1
  • This. I just now noticed the "Caching build: -node_modules" log output from heroku. Once I did a force push it worked for me. Thank you – Matteo Jan 11 '22 at 17:09
3

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.

2
  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
1

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.

tborges
  • 117
  • 1
  • 8
1

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

Akash J
  • 81
  • 1
  • 2
1

Was facing the same issue, however Yogesh's answer did not work for me. The app was running in my local however heroku failed to install dependencies. Noticed that I was using node 16.4.0 in local while heroku used 16.15.1. So I specified my local version in package.json, committed the changes and pushed to heroku and it started working.

    {
        "name": "leetboard-frontend",
        "version": "0.1.0",
        "private": true,
        "engines": {
            "node": "16.4.0"
        },

        .
        .
        .
    }

NUMBART
  • 52
  • 9
0

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.

Rami Salim
  • 182
  • 2
  • 11
0

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.

0

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

  • Answers must be self contained, & *exact code* necessary to solve a coding. issues must be embedded. See [help pages](StackOverflow.com/help) for more info. Links can be included, though Link only suggestions are not considered answers on SO either. Both are welcomed and appreciated as Comments. You can edit to include exact code, or repost as a Comment (once you have enough rep). – SherylHohman Nov 10 '20 at 16:31
0

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"
},
iByard
  • 1
  • 1
0

The following worked for me:

  1. Add the engines in your package.json. Try to match the node version with the one on your machine (you can check by running node -v in your terminal).

    "engines": {
    "node": "16.x"
    }
    
  2. Delete node_modules folder and package-lock.json

  3. Run npm install

  4. Make sure you are using the right buildpack. Run the following code, if your app is already using the correct buildpack it will tell you.

    heroku buildpacks:set heroku/nodejs
    
  5. You might be including node_modules in your source code. To find out run the following:

    git ls-files | grep node_modules
    
  6. If you get any results back, run the following to stop tracking node_modules:

    echo "node_modules" >> .gitignore
    echo "/lib" >> .gitignore
    git rm -r --cached node_modules
    git commit -am 'untracked node_modules'
    
  7. Finally, git add and commit your changes.

  8. Try pushing to Heroku again. Good luck and hopefully this helps.

Vahe Aslanyan
  • 76
  • 1
  • 4