14

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?

Aurora0001
  • 13,139
  • 5
  • 50
  • 53
stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94

1 Answers1

5

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'));
RyanZim
  • 6,609
  • 1
  • 27
  • 43
  • Thank you. This is a reasonable solution. The annoying thing is actually not exactly `leveldown` but `node-gyp`, it tries to download header files or current nodejs and then rebuild everything from scratch. But behind a corporate proxy, there will be some difficulties to download stuff from internet, especially when I easily upgrade nodejs (which means need to download corresponding header again) – stanleyxu2005 Aug 05 '17 at 18:45