3

Is there a way to run npm install but skip a particular dependency?

Something like:

npm install --skip=lodash --skip=rxjs

In my case, I have some developer tooling and some dependencies may not actually be in the NPM registry yet, so I want to skip those.

I am looking to skip installation of a particular dependency, and put a dummy package in its place.

Assuming this feature does not exist yet, I filed a related feature request on the NPM community forum: https://npm.community/t/allow-npm-install-to-work-with-missing-dependencies/1526

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

1

Did you try using "--no-optional" argument which will prevent optional dependencies from being installed.

sriharshay
  • 63
  • 9
  • that will skip the deps in the optional set, but not an arbitrary dependency, I am looking to skip installation of a particular dependency, and put a dummy package in its place. – Alexander Mills Sep 05 '18 at 19:52
  • This might help for some, but not for us: In our setup, external developers don't have a particular dependency and they do not need it. We can declare it as optional and they can use "no-optional", but that does not help, when they perform "npm install ..." to install a new package, then the resulting package-lock.json is incorrect. We then need to merge the file manually when we take over their work. – Darkwyng Dec 14 '20 at 15:39
1

Have you looked at npm link? If you have local customized versions of a package, such as say /home/me/hacked-npm/lodash, you can simply

  1. Run npm link from /home/me/hacked-npm/lodash

  2. cd to the project where you want to use the modified dependency

  3. Do your npm install and pull down everything like normal

  4. Run npm link lodash which will replace the lodash in that project's node_modules with a link that points to your hacked version in /home/me/hacked-npm/lodash.

I do this all the time when I want to use a hacked version of a dependency, works pretty well, and is expressly designed to solve the actual problem you're having (need to use a locally-modified version of a dependency)

Benji L.
  • 197
  • 11
  • 1
    The `npm install` will fail if a particular dependency is not yet hosted on NPM, I am looking to skip certain deps that are not in the NPM registry yet. – Alexander Mills Sep 05 '18 at 20:24
  • Did you try `link`-ing the packages before running `npm install`, so that they're already in `node_modules` before you run the install? If the deps are both new and not yet in a registry, then maybe remove them from the `package.json` and do your work by `link`ing them in rather than listing them as a hard dep. Once you publish the new modules you can add them back. – Benji L. Sep 05 '18 at 21:06
  • typically `npm install` deletes/overwrites the symlinks, which is a bug that NPM will fix with version 7. On the other hand, `yarn install` seems to have that problem covered already, so `yarn install` is currently the answer, see: https://stackoverflow.com/questions/51976626/keep-symlinks-when-running-npm-install – Alexander Mills Sep 05 '18 at 21:17
  • Basically, `npm install` will always break if you are pointing to the official NPM registry and a package is missing, I want to avoid that problem, using --skip or what not. The only other solution is to use a custom NPM registry, like verdaccio: https://github.com/verdaccio/verdaccio. – Alexander Mills Sep 05 '18 at 21:18