1

I know it's possible to specify a minimum version of node for a package to allow itself to be installed without warning.

There is also a question about [installing only the latest version your package is compatible with and nothing newer.]

However, in my case I am trying to make my package be compatible with hardware that is not able to run versions of node newer than 0.10.x. Specifically, this is hardware using ARMv5 processors, for which support was dropped in newer versions of V8. To do that, I need some polyfills, for example, os-homedir. I don't want to actually require that any such packages are installed if not needed because they are marked as deprecated, and in the above example the npmjs page for it is marked as not even in use, although I currently am able to npm install it.

How can I specify that a particular modular is only required if the version of nodejs present on the system is 0.10.x or older?

Michael
  • 9,060
  • 14
  • 61
  • 123

1 Answers1

0

What you are asking for is somewhat anti-semver, since you always have to install a specific version of your package. By calling npm install <package> you are simply asking for the latest version. Having npm roll back to older versions based on campatiblity might be confusing and not very "semver".

The current solution for this is the following:

Specify in your package.json the following:

{
   "engines" : {
       "node" : ">=0.10.3"
   }
}

now installing this package on a version of node older than 10.3 will cause it to fail. The user then must run npm view <package> versions and then install the appropriate version of the package by running npm install <package>@<version>

Bamieh
  • 10,358
  • 4
  • 31
  • 52