Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force ignore one dependency's dependency from being installed by npm/yarn

My nodejs project uses some libraries. One library pouchdb will try to install quite a lot of dependencies. There is one called leveldown, which will try to download Node.js header from Internet and then rebuild everything from scratch. Actually I don't need the leveldown at all. But their community suggest me to privately fork a pouchdb and the modify the package.json to exclude any dependency I don't need.

Here is my general question to npm/yarn folks. Is it possible to prevent particular library from being downloaded, while running npm install or yarn install?

like image 350
stanleyxu2005 Avatar asked Aug 05 '17 16:08

stanleyxu2005


People also ask

How do I skip a package in npm install?

To skip Installation of devDepenencies pass --production flag to npm install ,with the --production flag(or NODE_ENV environment variable set to production ) npm will not install modules listed in devDependencies." To make any module to be part of devDependencies pass --dev while installing.

How do you remove a dependency from a yarn lock?

If you run yarn remove [package] it will remove the package from node_modules and also from the yarn. lock file. If you manually delete from package. json and then run yarn install , the deleted package is not installed and the yarn.

How do I stop npm Installing with an unsupported node js version?

How to prevent npm install with an unsupported Node. js version. It turns out you can add a local npm configuration file ( . npmrc ) to your module/project root and explicitly turn on strict Node.

How install optional dependencies npm?

Execute npm install someDependency --save-optional to install a package as an optional dependency. The installed package will be put into optionalDependencies . When you want to avoid installing optional dependencies, you can execute npm ci --no-optional (e.g. on CI tools like GitLab CI).


1 Answers

No, it's not possible to exclude a sub-dependency from the installation.


However, in your case, you don't need to privately fork pouchdb. PouchDB has custom builds published as npm packages: https://pouchdb.com/custom.html.

If you want to install pouchdb for use in-browser, npm install pouchdb-browser.

If you're using other storage adapters (like the in-memory adapter), you may want to npm install pouchdb-core instead. Note that pouchdb-core doesn't include some functions that ship with pouchdb.

  • If you need to use query() or viewCleanup(), you need to install pouchdb-mapreduce and pass it as a plugin.
  • If you need to use replicate() and sync(), you need to install pouchdb-replication and pass it as a plugin.

Example usage:

const PouchDB = require('pouchdb-core')
  .plugin(require(WHATEVER_STORAGE_ADAPTER_YOU_ARE_USING))
  .plugin(require('pouchdb-mapreduce'))
  .plugin(require('pouchdb-replication'));
like image 165
RyanZim Avatar answered Sep 18 '22 15:09

RyanZim