Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a node_modules folder under my home folder?

I already have a global node_modules folder in /usr/local/lib/node_modules, but I just found there is also a ~/node_modules folder under my home folder. Can I delete this one?

I execute node -e "console.log(global.module.paths)" and I get:

[ '/Users/Username/node_modules',
'/Users/node_modules',
 '/node_modules' ]

And if I delete the node_modules folder, which is under the home directory, then I execute npm list @vue/cli-ui. It would should this error:

/Users/Username
└── UNMET DEPENDENCY @vue/[email protected]
npm ERR! missing: @vue/[email protected], required by Username

So, can I delete the node_modules folder under my home directory? What's the use of it? Or should I need reinstall Node.js and npm?

And if I do delete this folder, when I execute npm ls, I would get these errors:

/Users/Username
├─┬ UNMET DEPENDENCY @vue/[email protected]
│ ├─┬ UNMET DEPENDENCY @akryum/[email protected]
│ │ └── UNMET DEPENDENCY [email protected]
│ ├─┬ UNMET DEPENDENCY @vue/[email protected]
│ │ ├── UNMET DEPENDENCY [email protected]
│ │ ├── UNMET DEPENDENCY [email protected]
│ │ ├─┬ UNMET DEPENDENCY [email protected]
│ │ │ ├── UNMET DEPENDENCY [email protected]

How can I solve this problem?


Now everything is OK after executing npm cache verify.

like image 775
T.T Avatar asked Mar 06 '23 00:03

T.T


1 Answers

module.paths are the paths where Node.js search for NPM packages; and it actually doesn't search in your NPM global directory, as you can see.

More information is in Loading from the global folders and in All together....

You see those paths because you're executing node -e ... when you are in home directory, the Node.js simply traverse all node_modules paths to the root.

'/Users/node_modules',
 '/node_modules' ]

Relating to your question: Yes, you can delete ~/node_modules; probably it's there because you once wrote npm i MODULE without -g flag and your current working directory was ~.

like image 57
kopiro Avatar answered Mar 21 '23 08:03

kopiro