NPM: Never install nested optional dependencies fo

2020-07-05 07:07发布

问题:

I'm authoring a package A which I want to publish to NPM.

A has a dependency on package B, which in turn has a dependency on package C. C then has two optional native dependencies D and E. I know for definite I have no use for the optional dependencies, D and E, and NEVER want to try and install them when someone installs my package.

I know you can use the command npm install A --no-optional -g to install the package without optional dependencies, but this would be knowledge/overhead that I'd rather consumers of the package not need.

Is there any npm config or workaround where consumers of package A can just npm install A or npm install -g A and optional dependencies will never be installed?

Thanks

回答1:

npm install A --no-optional

Test to see if everything works.

npm list

Make sure you have no errors.

npm shrinkwrap

That will lock down the dependencies for the packages.

That way npm install will look into npm-shrinkwrap.json before trying to install dependencies.

You can read more about it here https://docs.npmjs.com/cli/shrinkwrap



标签: node.js npm