为什么我的主文件夹下有一个 node_modules 文件夹? [英] Why is there a node_modules folder under my home folder?

查看:117
本文介绍了为什么我的主文件夹下有一个 node_modules 文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 /usr/local/lib/node_modules 中有一个全局的 node_modules 文件夹,但我刚刚发现还有一个 ~/node_modulesem> 文件夹下我的主文件夹.我可以删除这个吗?

我执行 node -e "console.log(global.module.paths)" 然后我得到:

[ '/Users/用户名/node_modules','/用户/节点模块','/node_modules']

如果我删除主目录下的 node_modules 文件夹,然后我执行 npm list @vue/cli-ui.应该是这个错误:

/Users/Username└── 未满足的依赖@vue/cli-ui@3.0.1npm 错误!缺少:@vue/cli-ui@3.0.1,用户名需要

那么,我可以删除主目录下的 node_modules 文件夹吗?它有什么用?还是我需要重新安装 Node.js 和 npm?

如果我确实删除了这个文件夹,当我执行 npm ls 时,我会得到这些错误:

/Users/Username├─┬ UNMET 依赖 @vue/cli-ui@3.0.1│ ├─┬ UNMET DEPENDENCY @akryum/winattr@3.0.0│ │ └── 未满足的依赖 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

我该如何解决这个问题?


现在执行npm cache verify后一切正常.

解决方案

module.paths 是 Node.js 搜索 NPM 包的路径;它实际上不会在您的 NPM 全局目录中搜索,如您所见.

更多信息在从全局文件夹加载一起.......

您看到这些路径是因为当您在主目录中时正在执行 node -e ...,Node.js 只需遍历所有 node_modules 路径到根.

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

关于你的问题:是的,你可以删除~/node_modules;可能它在那里是因为你曾经写了 npm i MODULE 没有 -g 标志并且你当前的工作目录是 ~.

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.

解决方案

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

这篇关于为什么我的主文件夹下有一个 node_modules 文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆