Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force npm install to install optional dependencies for other platforms

I'm building a build task for Visual Studio Team Services. In this task I'm using 7zip-bin to package the binary for 7zip for linux, mac and windows.

This is all nice and it would work if I had the ability to deploy just the package.json to the build server, but no... A build task contains all its dependencies at build time.

Is there a way I can force npm to download all OS optional packages somehow? Or will I have to download the file myself during build and extract it?

Right now I'm using

npm install 7zip-bin --save

Which results in:

C:\temp>npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: 7zip-bin-linux@^1.0.3 (node_modules\7zip-bin\node_modules\7zip-bin-linux):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: 7zip-bin-mac@^1.0.1 (node_modules\7zip-bin\node_modules\7zip-bin-mac):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

installing each optional package directly isn't possible, when I run

npm install 7zip-bin-linux --save

on a windows machine, the install is skipped and I get a EBADPLATFORM error.

I understand I can't run these on my machine, but I need to package them in a vsix file (a glorified zip) so I can use them when my build task is running on these other platforms.

like image 651
jessehouwing Avatar asked Feb 22 '17 16:02

jessehouwing


People also ask

Does npm install install optional dependencies?

By default, npm install will install all modules listed as dependencies in package.json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .

How do I force an NPM package to install?

The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk. The -g or --global argument will cause npm to install the package globally rather than locally.

How do I install npm globally?

Install Package Globally NPM can also install packages globally so that all the node. js application on that computer can import and use the installed packages. NPM installs global packages into /<User>/local/lib/node_modules folder. Apply -g in the install command to install package globally.

How npm install specific dependencies?

Summary. For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.


1 Answers

You should depend on these 3 optional packages, because you never know if 7zip-bin will change it's optional dependencies, which you are using directly.

For example:

dependencies: {
  "7zip-bin-mac": "^1.0.1",
  "7zip-bin-win": "^2.0.2",
  "7zip-bin-linux": "^1.0.3"
}

Using either way, you need to run npm install -f to force the installation.

like image 77
Frank van Wijk Avatar answered Oct 07 '22 19:10

Frank van Wijk