简体   繁体   English

如何防止npm安装 <package> --save-dev从重新排序devDependencies

[英]How to prevent npm install <package> --save-dev from reordering devDependencies

Background 背景
We're having issues with a Windows build system hitting the file path too long error when the node modules folder has items within it that have paths which are over 260 characters. 当节点模块文件夹中包含路径长度超过260个字符的项目时,Windows构建系统遇到文件路径太长错误的问题。

We've discovered adding a deeply nested dependency to the top of the devDependencies section fixes this issue. 我们发现在devDependencies部分的顶部添加了一个嵌套嵌套的依赖项,可以解决此问题。 The assumption is that when npm sees a nested dependency C.1 require package A , which is already declared and available in devDependencies, npm will not add dependency A to dependency C.1 's node_modules directory. 假设是,当npm看到嵌套的dependency C.1要求package A ,该package A已经在devDependencies中声明并可用,npm不会将dependency A添加到dependency C.1的node_modules目录中。

Issue 问题
The problem I'm seeing on my local machine is that running npm install <package> --save-dev reorders the packages in devDependencies alphabetically, but the order npm process packages and their dependencies matters. 我在本地计算机上看到的问题是,运行npm install <package> --save-dev按字母顺序对devDependencies中的程序包进行重新排序,但是npm处理程序包及其相关性的顺序很重要。 If I check this in, then the build system will hit the same file path too long error. 如果我签入,那么构建系统将遇到相同的文件路径过长的错误。

ie If package A comes after package C and dependency C.1 requires package A , then npm will add package A to the node_modules folder of dependency C.1 . 例如,如果package Apackage C并且dependency C.1需要package A ,则npm会将package A添加到dependency C.1的node_modules文件夹中。

I'm not sure if this reordering is only on my machine since I haven't seen npm reorder dependencies on my home machine before. 我不确定这种重新排序是否仅在我的机器上,因为我以前没有在家用计算机上看到过npm重新排序依赖项。

Has anyone seen this before or know how to stop this behavior? 有没有人看过这个或知道如何停止这种行为?

Versions 版本
Node: v0.10.32 节点:v0.10.32
NPM: v1.4.28 NPM:v1.4.28

Side note: I've read that npm 2.0 or future versions will analyze the dependency hierarchy, find duplicated packages, and only reference them once on the file system, but the upgrade to npm 2.0 is not in the picture at this time. 旁注:我已经读过npm 2.0或更高版本将分析依赖关系层次结构,查找重复的程序包,并且仅在文件系统上引用它们一次,但是此时未升级到npm 2.0。

The only way I see this working is to have some sort of preinstall script which [hopefully] will run after the dependencies file has been updated but before the package is installed. 我看到此工作的唯一方法是拥有某种预安装脚本,希望该脚本在更新依赖项文件之后安装软件包之前运行。 From the npm site : 从npm网站

In the current version of node, the standard way to do this is using a .gyp file. 在当前版本的节点中,执行此操作的标准方法是使用.gyp文件。 If you have a file with a .gyp extension in the root of your package, then npm will run the appropriate node-gyp commands automatically at install time 如果您的软件包根目录中具有扩展名为.gyp的文件,则npm将在安装时自动运行相应的node-gyp命令

If that doesn't work, you will need to use MakeFile and rewrite the package.json file. 如果这样不起作用,则需要使用MakeFile并重写package.json文件。 This is not too out of the ordinary as some projects require some sort of pre-compilation - you would just instruct your team to run a separate command for installing npm packages. 这并不是太不寻常,因为某些项目需要某种预编译-您只需指示您的团队运行一个单独的命令来安装npm软件包。

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

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