0

I built my Electron app using the standard example app that is provided which includes a lot of node modules. There are over 200 node modules and many of them I don't need. I want to remove all those I don't need but it isn't clear how to determine that. Some of the ones I need have dependency modules and I have no way of determining which ones those are. Aside from just removing what I think I don't need and testing the app to see if it works properly, is there some more quick and accurate way of determining which modules I need?

In my package.json file there are several modules listed in the dependency section. If I delete all the node modules and rerun the app, the ones listed in the package.json file are installed but so are hundreds more. I cannot tell whether all those other ones are absolutely needed or whether the npm start command just grabs everything related to the ones in the package.json file.

Johann
  • 27,536
  • 39
  • 165
  • 279
  • Depending on your npm version, dependencies are installed in a flat structure in your `node_modules` folder with `> npm v2.x.x`. If you have referenced all of the modules you need in your `package.json` file, a clean npm install (`rm -rf node_modules && npm install`) will only install those modules and their required dependencies. – bradcush Aug 21 '18 at 15:39
  • I did as you suggested and was surprised that it installed all those hundreds of files. I can assume that they are dependencies but that doesn't mean that they are actually required. I suspect that whoever created those dependencies just added everything even if my app doesn't need it. – Johann Aug 21 '18 at 15:45
  • Most likely, the majority of those modules are in fact necessary. Having hundreds of modules installed with only 5-10 in your package.json is normal. – Kevin B Aug 21 '18 at 15:53
  • @AndroidDev They are dependencies of the dependencies you have specified in your `package.json`. Those packages themselves need them whether you explicitly use them or not. – bradcush Aug 21 '18 at 16:50

3 Answers3

0

Try the tool depcheck: https://www.npmjs.com/package/depcheck. Install it by running npm install depcheck. However you might want to be a bit careful with it as I have gotten since false alarms using it. Make sure to read the documentation as I think they have certain ways of preventing those false alarms with rules you can specify.

Joshua Avery
  • 314
  • 2
  • 17
  • I just came across that and tried it out. It clearly reports false dependencies. I'm surprised that anyone uses it. – Johann Aug 21 '18 at 15:29
  • Do you happen to use a different syntax? They support typescript and others. – Joshua Avery Aug 21 '18 at 15:36
  • Just plain old javascript where modules are used with the "require" method. – Johann Aug 21 '18 at 15:39
  • Some modules use typescript I believe. However try out some of the suggestions made in this thread https://stackoverflow.com/questions/22675725/find-unused-npm-packages-in-package-json – Joshua Avery Aug 21 '18 at 15:42
0

first, open vs Code. then go for the selected level of the file if you kept node module in any other place. "CHECK the Image open Git Bash in terminal"

PAst : $ [rm -rf ./node_modules].... last step:- Past this line of code enter image description here rm -rf ./node_modules

-1

If you have access to unix tools, do a grep throughout your entire project for "require(" and that will give you a list of every module that is at least explicitly included in the project.

Prodigle
  • 1,757
  • 12
  • 23