3

In npm, how do i install a single package without the rest of the dependencies in the list, because if i install on dependency e.g. npm i express all other dependencies get installed as well. How do i prevent this and have only express installed

EDIT The other question has a very complicated answer of creating a bash file, am not willing to go that far, i want a simpler answer

lulliezy
  • 1,741
  • 5
  • 24
  • 49
  • npm simply doesn't offer a built-in feature to achieve what you're asking for [period]. Custom requirements require custom solutions - hence the bash/shell script suggested in that [answer](https://stackoverflow.com/questions/28382773/install-npm-package-without-dependencies). – RobC Apr 09 '18 at 12:58
  • 2
    Exact duplicate of [Install only one package from package.json?](https://stackoverflow.com/questions/22420564/install-only-one-package-from-package-json). – Dan Dascalescu Apr 04 '21 at 04:28

1 Answers1

2

To avoid installing optional dependencies, you could use the option: --no-optional it is supported according to this link of the docs :

The --no-optional argument will prevent optional dependencies from being installed.

Also, there are dependencies which are not optional, you can't stop them from being installed since the package has a direct dependency.

Kenny Alvizuris
  • 435
  • 4
  • 6
  • currently no dependencies are installed, out of all in the list, i want only one but installing that one installs all, this is the problem – lulliezy Apr 09 '18 at 11:45
  • Based on your example, for `express` you can see that it has 30 `dependencies` and 18 `dev-dependencies` [here](https://www.npmjs.com/package/express?activeTab=dependencies). You can also read more about the difference in this great explanation. [here](https://stackoverflow.com/a/22004559/9492453) these dependencies will be installed inside your `node_modules/express` and they are required for express to work properly. – Kenny Alvizuris Apr 09 '18 at 11:50
  • well i just had to copy the entire folder from where it was already installed to the node_modules folder of this dir – lulliezy Apr 09 '18 at 11:51
  • Could you give me an example? I can't understand what you are facing. – Kenny Alvizuris Apr 09 '18 at 11:51
  • actually installing express only installs one package, the other packages are on a need to use basis – lulliezy Apr 09 '18 at 11:51
  • Yes correct, if you do `npm i express` it will install one package and inside its dependencies inside `node_modules/express`. – Kenny Alvizuris Apr 09 '18 at 11:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168558/discussion-between-kenny-alvizuris-and-lulliezy). – Kenny Alvizuris Apr 09 '18 at 11:54
  • 1
    on my front end, i only need the dependencies for bundling, but i have one more dependency which is express to host the app, now i don't need the other dependencies since i have already bundled my js file, but i need express to run app, so installing express only is not possible – lulliezy Apr 09 '18 at 11:54
  • the other solution i thought is making all dependencies optional then use the `--no-optional` argument – lulliezy Apr 09 '18 at 12:07
  • No effect, why? – Jeff Tian Oct 31 '21 at 10:44