Specify an npm version

A npm dependency I am trying to install in a glitch node app is sails which requires being installed with an npm version less than 3.

details

Sails supports npm >= 3 by copying the sails node_module into a sub folder. As sails and its dependencies are over 50 MB, you run out of diskspace on glitch when it copies. In npm < 3 symlinks are used instead which lets you create a project without running out of disk space on glitch.

I tried adding “npm”:"~2" to engines in package.json but it does not look like it is respected.

I can npm i npm@2 and then add ./node_modules/.bin to the path with PATH=./node_modules/.bin/:$PATH and then tweak package.json to get npm install to run with the correct npm version, but that gets lost when the container spins down.

Is there a way to enforce an npm version to use and / or a way to have a start-up script that runs before dependencies are installed so I can modify the PATH?

1 Like

You can modify the node version through engines.node in package.json… I think node 4 had npm < 3

2 Likes

Would be preferable to be able to use a newer node.js version but that workaround does work for now! Thanks!

Updated the package.json to have engines.node as “4.x” and in the activity log got

node v4.8.5, npm 2.15.11

1 Like

Hi Milan :slight_smile:

we just released a change that makes the binaries in node_modules/.bin to take precedence over those in the Node distribution, so you don’t need to use an older node version to use npm anymore :slight_smile: Just install the version of npm you prefer, and then the next time you run npm install, it would use that version :slight_smile:

Let us know if you have any issue!

2 Likes