npm installs many dependencies

Viewed 2833

I bought a HTML template recently, it contains many plugins placed inside bower_components directory and a package.js file inside. I wanted to install another package I liked, but decided to use npm for this purpose.

When I typed:

npc install pnotify

node_modules has been created containing about 900 directories with another packages.

What are those? Why did they get installed along with my package? I did some research and turned out that those are needed but really, do I need to deliver my template in production with hundreds of unnecessary packages?

6 Answers

What are those? Why did they get installed along with my package?

Dependencies exists to facilitate code reuse through modularity.

... do I need to deliver my template in production with hundreds of unnecessary packages?

One shouldn't be so quick to dismiss this modularity. If you inline your requires and eliminate dead code, you'll lose the benefit of maintenance patches for the dependencies automatically being applied to your code. You should see this as a form of compilation, because... well... it is compilation.

Nonetheless, if you're licensed to redistribute all of your dependencies in this compiled form, you'll be happy to learn those optimisations are performed by a compiler which compile Javascript to Javascript. The Closure Compiler, as the first example I stumbled across, appears to perform advanced compilation, which means you get dead code removal and function inlining... That seems promising!

This does however have another side effect when you are required to justify the licensing of all npm modules..so when you have hundreds of npm modules due to dependencies this effort also becomes a more cumbersome task

Very old question but I happened to come across very similar situation just as RA pointed out.

I tried to work with node.js framework using vscode and the moment when I tried to install start npm using npm init -y, it generated so many different dependencies. In my case, it was vscode extension ESlint that I added to prior to running npm init -y

  • Uninstalling ESlint
  • Restarted vscode to apply that uninstallation
  • removed previously generated package.json and node-modules folder
  • do npm init -y again

This solved my problem of starting out with so many dependencies.

Related