简体   繁体   English

如何取消节点模块?

[英]How can I unflatten the node module?

My current npm version is 3.7.3 . 我目前的npm版本是3.7.3。 Previously, only the required packages were getting installed in my node modules. 以前,我的节点模块中只安装了所需的软件包。 But right now they have all flattened and have 100 + folders visible when I look into node modules. 但是现在,当我查看节点模块时,它们已经变平并且有100 +个文件夹可见。 I prefer the older way where you could go into individual folders and see their dependencies. 我更喜欢旧的方式,您可以进入单个文件夹并查看其依赖项。 here is a similar thread: Why does npm install many packages into "/node_modules" instead of only one? 这是一个类似的线程: 为什么npm将许多软件包安装到“/ node_modules”而不是只有一个?

I tried running npm uninstall without much success. 我尝试运行npm uninstall没有太大的成功。

Basically, you are out of luck... NPM does not provide any configuration options regarding this. 基本上,你运气不好...... NPM没有提供任何关于此的配置选项。 It will nest dependencies if it must in order to resolve version conflicts, but only in this case. 如果必须为了解决版本冲突,它将嵌套依赖项,但仅限于此情况。 Your only option is to downgrade NPM (not recommended). 您唯一的选择是降级NPM(不推荐)。 However, if you just need to see the dependencies nested for informational reasons, you can use npm ls . 但是,如果您只是出于信息原因需要查看嵌套依赖项,则可以使用npm ls It will draw you a graph. 它会画出一个图表。

See this relevant NPM issue for more discussion: https://github.com/npm/npm/issues/9809 有关更多讨论,请参阅此相关NPM问题: https//github.com/npm/npm/issues/9809

Now that node js' LTS doesn't include an NPMv2 I found myself stuck with this issue again. 既然节点js'LTS不包含NPMv2,我发现自己又遇到了这个问题。 For those of you also caught out, the link that @KevinBurdett mentioned, also has some answers. 对于那些你也被发现的人来说 ,@ KevinBurdett提到的链接也有一些答案。

You can force downgrade npm using npm itself (using sudo or equivalent for this). 可以使用npm本身强制降级npm(使用sudo或等效的)。 From https://github.com/npm/npm/issues/9809#issuecomment-179702479 : 来自https://github.com/npm/npm/issues/9809#issuecomment-179702479

as root I simply do npm install -g 'npm@<3' on my system every time I a new version of Node comes out; 作为root用户每次我发布一个新版本的Node时,我只需在我的系统上执行npm install -g 'npm@<3' ; your mileage might vary, but it's fairly trivial to "downgrade" :-) 你的里程可能会有所不同,但“降级”是相当微不足道的:-)

Another alternative is to use the Node Version Manager (NVM): https://github.com/creationix/nvm . 另一种方法是使用节点版本管理器(NVM): https//github.com/creationix/nvm Your mileage may vary depending upon personal config/preferences/platform. 您的里程可能因个人配置/偏好/平台而异。

That said, npm 3 and the issue of flat dependency trees will be with us from hereafter... It's probably high time to start accepting that change. 那就是说,npm 3和平依赖树的问题将从今后开始......现在可能是开始接受这种变化的时候了。

My personal grudge with this is that it makes the node_modules folder incredibly difficult to work with in an IDE, especially when you need to look at the implementation of your immediate dependent modules, without first wading through 100's of sub-sub modules that are irrelevant to me. 我个人的怨恨是,它使得node_modules文件夹难以在IDE中使用,特别是当您需要查看直接相关模块的实现时,而不首先涉及100个与子模块无关的子模块我。 It seems that I'm not alone in this matter when you read the comments in the issue. 当你阅读这个问题的评论时,我似乎并不孤单。 It only leads me to question the viability of npm itself when such changes are made without a proper migration from old to new systems. 当没有从旧系统到新系统的适当迁移进行此类更改时,它只会让我质疑npm本身的可行性。 For me, npm2 will always be king. 对我来说,npm2永远是王道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM