I'm attemting to modify an npm package with multiple dependencies. As such npm install -g . takes a long time to execute. Do I have other options besides removing the dependencies from packages.json?
- 1,391
- 3
- 13
- 26
-
I think this question is a better fit for SO, and was asked there before this one - [Install only one package from package.json?](https://stackoverflow.com/questions/22420564/install-only-one-package-from-package-json). It also has updated answers. – Dan Dascalescu Apr 04 '21 at 10:16
-
I’m voting to close this question because I believe it belongs to SO, and had been asked there already. – Dan Dascalescu Apr 04 '21 at 10:16
4 Answers
--no-optional option is now implemented according to this documentation https://docs.npmjs.com/cli/install :
The --no-optional argument will prevent optional dependencies from being installed.
- 346
- 2
- 2
If you're developing that node_module yourself, don't waste your time on npm installs, instead use npm link.
In short, you create a symbolic link to your module folder on an npm-owned global folder, and then in your app folder you ask npm to use that symbolic linked folder.
This makes changes you make in the module folder to be reflected immediately in your app.
Here are the main steps (copied from the tutorial linked below, make sure to read the tutorial for important gotchas):
- cd to
src/my_module - Run "
npm link". This creates a symbolic link from a global folder to thesrc/my_modulefolder. - cd to
src/my_app - Run
npm link my_module. This linksnode_modules/my_modulein this particular project to the global folder, so thatrequirecalls looking formy_modulewind up loading it from your development folder,src/my_module.
See this tutorial: http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears
And the official docs for npm link: https://docs.npmjs.com/cli/link
- 231
- 2
- 3
-
Not changing my accepted answer, but upvoting because this is useful for my specific case. – Justin Dearing Jan 17 '17 at 14:53
This feature was requested back in 2010, but unfortunately was ignored and closed: https://github.com/npm/npm/issues/340
I tried a bunch of options, and finally found a pretty simple solution - rename package.json to something else before doing npm install, then revert it back to after install finishes:
mv package.json package.bak
npm install <package_name> --no-save
mv package.bak package.json
- 1,878
- 2
- 18
- 22
- 191
- 1
- 2
-
3Wow, is that seriously still the only way? That's ridiculous, there should be a flag `--ignore-package` or something. – JacobTheDev Oct 12 '18 at 20:42
-
3This solution is good and so far it may be the best solution for my question: https://stackoverflow.com/questions/53532845/how-to-install-only-babel-related-devdependencies-in-package-json – aGuegu Nov 29 '18 at 19:46
Looking through the docs it doesn't appear to have an option beyond the --no-optional switch.
Untested/uncomfirmed
This SO Q&A titled: npm install installs all dependencies of my project over the network, even if they are already installed or available from cache would seem to imply there's a --skip-installed switch. But the docs do not make any reference to this switch.