node.jsnpmvue-cli-3

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/cli-ui@3.0.1
npm ERR! missing: @vue/cli-ui@3.0.1, 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/cli-ui@3.0.1
│ ├─┬ UNMET DEPENDENCY @akryum/winattr@3.0.0
│ │ └── UNMET DEPENDENCY fswin@2.17.1227
│ ├─┬ UNMET DEPENDENCY @vue/cli-shared-utils@3.0.1
│ │ ├── UNMET DEPENDENCY chalk@2.4.1
│ │ ├── UNMET DEPENDENCY execa@0.10.0
│ │ ├─┬ UNMET DEPENDENCY joi@13.6.0
│ │ │ ├── UNMET DEPENDENCY hoek@5.0.4

How can I solve this problem?


Now everything is OK after executing npm cache verify.


Solution

  • 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 ~.