Is there any way to know whether an npm package has OS specific build requirements?

538 Views Asked by At

Some node modules have specific platform install requirements. For example, node-sass cannot be built on a mac and used on windows or linux. It can run on windows, but only if you build it on windows. Because of its node-gyp dependency, it must be specifically built on the platform for which you intend to run it.

Whereas lodash has no such complexity.

Is there any (ideally, automatic or programmatic) way to know which packages work like node-sass, and which work like lodash, apart from reading the documentation for each package/manually experimenting?

I want to mount my node_modules directory to a docker container, but I want to install my node modules locally on the host. That doesn't work for any modules such as node-sass.

2

There are 2 best solutions below

4
M.Elkady On BEST ANSWER

You can check the package.json for os and also if the package need build like the answer here Node.js / npm - anyway to tell if a package is pure JS or not? But in general, it's not right to install node_modules locally on the host and mount it this against the main idea of docker to run the same image anywhere with zero configuration or dependency

1
Mureinik On

The package.json file should specify any OS limitations the package has using the os property, e.g. "os" : [ "darwin", "linux" ] or even "os" : [ "!win32" ].

Having said that, there's no real way of enforcing the use of this property, and a package author can just omit (or forget!) to specify the os property in the package.json file but still write a package that will only work on a certain operating system.