stackdave stackdave - 1 year ago 119
Node.js Question

npm and node versions incompatible can produce error

I've installed nodenv to manage versions of node and npm in my pc. Because when I try install packages like , angular-cli, webpack , typescript, angular2 and another, I get errors

FIRST QUESTION: Can an version node or npm produce error when i install a package?

Some packages tells things like: "The generated project has dependencies that require Node 4.x.x and NPM 3.x.x."

but they don't mention the exact version. by example Can a version of node 4.1.5 produce errors and not the version 4.0.5 ?

I don't like these packages need be installed like global (-g) and the problems i see sometimes there are conflicts between global packages installed.
Example error:

npm WARN EPEERINVALID string-replace-loader@1.0.3 requires a peer of webpack@1.x.x || 2.x.x but none was installed.

PhantomJS not found on PATH

but what about if two global packages use same global package, but some of they use a different version for every package?

Answer Source

Its up to npm package owners to define in their package.json all the upstream dependencies with a set of working versions which play well together ... challenge is as a package owner to make your package.json loose as possible regarding upstream dependencies to enable pulling in newer releases of these dependent packages yet tight enough that your published package still works

Often this is not the case which can lead to version mismatch invoked errors ... if possible always use most recent package releases this goes for nodejs itself as well

When package.json mentions versions such as 3.x.x it means it should work with any value of x.x so just chose the highest number to fit the pattern

Where possible avoid doing a global install unless it is for command line executables ... this is especially true for packages which your code pulls in as opposed to an executable centric package

UPDATE I am now able to successfully install this

npm install -g angular-cli

using the latest release of node

node --version

so I suggest you upgrade your own project code and node version to avoid that pinned release which fails and work with the most current releases

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download