Heroku does not read node version

I have a Node project that I want to host on Heroku. I explicitly defined the Node and npm versions in my package.json (located in the root directory), which looks like this:

{ "name": "*********", "version": "0.0.0", "private": true, "engines": { "node": "0.12.x", "npm": "2.5.x" }, "scripts": { "start": "node ./bin/www" }, "dependencies": { "body-parser": "^1.13.3", ... } 

However, when I try to press the application on heroku

 git push heroku master 

Heroku is trying to build an application, but it seems it cannot use the version of Node and npm. Here is the answer I get.

 remote: -----> Installing binaries remote: engines.node (package.json): unspecified remote: engines.npm (package.json): unspecified (use default) remote: remote: Resolving node version (latest stable) via semver.io... remote: Downloading and installing node 4.2.1... remote: Using default npm version: 2.14.7 

Why doesn't the hero read the version of Node and npm from package.json?

+7
json heroku
source share
4 answers

@rdegges was right that package.json was not passed to Heroku correctly. So, following Heroku's instructions, for some reason, did not work for me. Here is what I had to do to make it work.

 git clone <my git project> heroku create <app name> #remove package.json mv package.json tmp_package.json git add package.json git commit -m "removed package.json" #re-add package.json mv tmp_package.json package.json git add package.json git commit -m "re-added package.json" git push heroku master 
+3
source share

This works for me - make sure you really make these changes in Git and push the repository to Heroku. You can also specify the exact Node and NPM version numbers for your Heroku application.

While it WILL WORK with the versions of variables you specify, this is not recommended, as small changes in releases may cause problems for you.

For reference, here are the Heroku docs on determining Node.js runtime: https://devcenter.heroku.com/articles/nodejs-support#node-js-runtimes

0
source share

I tried other solutions, but this did not work for me. However, changing the name field in package.json, it worked:

From:

 { ... "name": "foo" ... } 

To:

 { ... "name": "bar" ... } 

Alternative 2 :

When I had to do the same on my other computer, it did not work, but I tried to remove package.json , recreating it from scratch, and then it worked for some odd reason (file metadata?):

 $ rm package.json $ npm init 
0
source share

Perhaps your main branch is not a branch, it is not updated, try merging the branch that you want to expand into the wizard to use:

 git push heroku master 
0
source share

All Articles