npm doesn't work with node v0.8.5? - node.js

I'm deploying a Node app to Heroku and get the following error. If npm doesn't work with recent versions of Node, what are we supposed to use for a package manager? I really liked node_modules and package.json. It seemed very logical.
-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.8.5
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
Error: npm doesn't work with node v0.8.5
Required: node#0.4 || 0.5 || 0.6

If you're specifying Node.js 0.8.x via "engines" in your package.json, you may also need to set a version for "npm":
{
...
"engines": {
"node": "0.8.x",
"npm": "1.1.x"
}
}
From the Heroku Dev Center for Node.js:
If you do not specify a version, you will get the following defaults:
Node.js: 0.4.7
npm: 1.0.106
That page also includes links to supported version manifests for both.

You've simply got an obsolete version of npm: the current version is 1.1.45 and works just fine with 0.8.x versions of node.

Related

Heroku Unable to Properly Use NPM_CONFIG variable at deploy

I am using a private package from GitHub. When attempting to deploy, Heroku ignores my .npmrc file configs.
Locally, my environment file looks like:
NPM_CONFIG_GITHUB_TOKEN=[token]
Then, my .npmrc file looks like this:
[username]:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN
With this configuration, I'm able to run this locally just fine. In Heroku, I get the following error:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_GITHUB_TOKEN=[token]
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 12.13.x
engines.npm (package.json): unspecified (use default)
Resolving node version 12.13.x...
Downloading and installing node 12.13.1
Using default npm version: 6.12.1
-----> Restoring cache
Cached directories were not restored due to a change in version of node, npm, yarn or stack
Module installation may take longer for this build
-----> Installing dependencies
Installing node modules
npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download/[package]
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.P5iPk/_logs/2020-08-03T18_44_16_744Z-debug.log
-----> Build failed
The full logs say the same thing. However, if I change .npmrc to:
[username]:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
... It work just fine in Heroku, but breaks locally.
Can anyone offer some guidance on what I'm doing wrong here? I've researched this for hours with no success. While the obvious solution is a different local version, this is an opensource project and I want to be able to provide straightforward installation directions.
When I deploy to Heroku I usually set the environment variables in my app settings on Heroku and I've never had a problem, you could try that

heroku fails to create app from default node-js-sample

I forked node-js-sample and made just added index.htm with some content
When I click the button "Doploy to heroku" app fails to build with following error:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 4.0.0
engines.npm (package.json): unspecified (use default)
Resolving node version 4.0.0...
Downloading and installing node 4.0.0...
Detected package-lock.json: defaulting npm to version 5.x.x
Bootstrapping npm 5.x.x (replacing 2.14.2)...
npm 5.x.x installed
ERROR: npm is known not to run on Node.js v4.0.0
Node.js 4 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 4.7.0 to use this
version of npm. You can find the latest release of Node.js at
https://nodejs.org/
ERROR: npm is known not to run on Node.js v4.0.0
Node.js 4 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 4.7.0 to use this
version of npm. You can find the latest release of Node.js at
https://nodejs.org/
ERROR: npm is known not to run on Node.js v4.0.0
Node.js 4 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 4.7.0 to use this
version of npm. You can find the latest release of Node.js at
https://nodejs.org/
-----> Change to Node.js build process
Heroku has begun executing the "build" script defined in package.json
during Node.js builds.
Read more: https://devcenter.heroku.com/changelog-items/1573
-----> 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
From what I understand heroku try to runs my code with incorrect version of node.js, but why?
The repository hasn't been updated in 4 or more years and still depend on node.js 4 and lists the same on the package.json. It is a compatibility issue, before deploying change it to 6.0.0 and try, you might have luck.
Ran into the same issue recently which was a real pain, found a solution here https://devcenter.heroku.com/articles/nodejs-support
Currently, supported versions are 10.x, 12.x, 13.x, and 14.x.
You should always specify a Node.js version that matches the runtime
you’re developing and testing with.
Updated node globally and specified the engine in package.json like:
"engines": {
"node": "10.20.x"
},
Hope this helps someone

How to specify npm version when deploying nodejs apps to bluemix?

I created a node.js application with runtime dependencies of scoped packages in my package.json:
"dependencies": {
"#shawnzhu/mybot" : "latest",
...
},
"engines": {
"npm": ">2.0.0",
"node": "0.10.38"
},
I also have a custom .npmrc that points scope #shawnzhu to my private npm registry.
Currently it works when deploying to heroku, where it upgrades npm to v2.7.x. However, a cf push to bluemix fails with the console output showing:
registry "#shawnzhu/mybot" not found.
After reviewing the whole console output I realized it uses npm v1.4.28 which doesn't support scoped packages.
How can I get npm v2.0.0+ in a node.js app in bluemix?
Before June 15, 2015: This was not possible using the default Node.js buildpack on Bluemix, yet. For now, you can use the community open-source Node.js buildpack:
cf push mynodeapp -b https://github.com/cloudfoundry/nodejs-buildpack
You've specified the npm version in your package.json correctly, so it should work for the community buildpack.
After June 15, 2015: The newest version of the IBM Node.js Buildpack is now available on Bluemix! You can see the full changes at https://developer.ibm.com/bluemix/2015/06/15/bluemix-node-js-buildpack-update/
This buildpack comes with the ability to specify NPM versions by including an "npm" entry in your package.json, like so:
"engines": {
"npm": "xxxxxxx"
},
I was also able to get this working using Node 0.12.2, with the following changes:
In package.json:
"engines": {
"npm": ">2.0.0",
"node": ">=0.12.0"
},
As of the latest Bluemix node.js default buildpack (c.Jun 4, 2015), you can specify a version of npm >2.0.0, which installs a version of npm >2.7, which is the requirement to support and import scoped npm packages. I have tested this for a publicly scoped package and it is up and running in production in Bluemix, using the default node.js buildpack.
If you don't want to revert and use the cf community buildpack, you can use the "engines.npm" property and that should get you up and running, even in node 0.10.x.
In package.json, specify:
"engines": {
"npm": ">2.0.0",
"node": "0.10.x"
}
I've edited this answer for clarity. Many thanks to #shawnzhu for comments. Hope this helps.

Custom node.js version on Openshift

I am having trouble running custom node version on node0.10 cartridge on open shift which you can find here.
I get to install the new node version just great, however open shift keeps using the old node 10.25.
Deoploy log:
remote: Activating deployment
remote: - Checking to see if Node.js version 0.10.33 is installed ...
remote: - Node.js version 0.10.33 is already installed
remote:
remote: - pre_start_nodejs: Adding Node.js version 0.10.33 binaries to path
remote: -this is the path: /var/lib/openshift/54b6ea6e4382ece151000039/app-root/data/node-v0.10.33-linux-x64/bin:/var/lib/openshift/54b6ea6e4382ece151000039/app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/54b6ea6e4382ece151000039//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin
remote: - PATH set to include custom node version (0.10.33) from
remote: /var/lib/openshift/54b6ea6e4382ece151000039/app-root/data/node-v0.10.33-linux-x64/bin
remote: PATH = /var/lib/openshift/54b6ea6e4382ece151000039/app-root/data/node-v0.10.33-linux-x64/bin:/var/lib/openshift/54b6ea6e4382ece151000039/app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/54b6ea6e4382ece151000039//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin
remote: Starting NodeJS cartridge
Everything looks great and awesome, until I run the app which says: 10.25...
rhc tail:
v0.10.25
/opt/rh/nodejs010/root/usr/bin:/opt/rh/v8314/root/usr/bin:/var/lib/openshift/54b6feb9e0b8cd56c00000e1/app-root/data/node-v0.10.33-linux-x64/bin:/var/lib/openshift/54b6feb9e0b8cd56c00000e1/app-root/runtime/repo/node_modules/.bin:/var/lib/openshift/54b6feb9e0b8cd56c00000e1//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin:/bin:/usr/bin:/usr/sbin
undefined
Even when i rhc ssh to my app and try node -v i get 10.33...
on start time the PATH env gets overwritten and causes node to use the old bins...
PS: I am trying to deploy a Meteor app (1.0.2.1)
Nevermind, figured it out :-)
If you want to use custom node #openshift take a look at this repo.
Hope I get to help someone!

Heroku does not respect npm-shrinkwrap.json

I have a Node.js app with npm-shrinkwrap.json checked in. When I run npm install locally, it installs the versions specified in npm-shrinkwrap.json, but when I push it to Heroku (on the Cedar stack), it seems to ignore the shrinkwrap and simply installs the newest version.
Am I doing something wrong? I don't need to to check in node_modules, do I?
As you say in your answer, when Heroku wrote the Nodejs buildpack, the feature npm shrinkwrap didn't exist.
However, as of version 1.1.2, npm install tries npm-shrinkwrap.json first, falling back to package.json. This means that Heroku respects it (even though the feature hadn't been conceived when Heroku wrote their code). Isaacs is awesome.
So just add to your package.json:
"engines": {
"node": "0.8.x",
"npm": ">=1.1.2"
}
Then run npm shrinkwrap, and git add npm-shrinkwrap.json. Then commit as normal.
As it turns out, Heroku uses npm 1.0.106 at the moment, but shrinkwrap was only added in npm 1.1.2, according to the changelog.
Adding node_modules has solved my problem, until Heroku upgrade their npm.

Resources