npm 安装失败,因为注册表中缺少包

npm install fails because package is missing in registry

我在使用 node 和 brunch 的项目中遇到问题。该问题当前特定于早午餐,但我猜任何模块都可能发生。

目前重现此问题的最简单方法是在新文件夹中执行以下操作:

npm init
npm install --save-dev brunch

这里的问题是 brunch 依赖于 loggy,而 loggy 又依赖于 ansi-color,后者在 npmregistry 中不再有条目:

https://registry.npmjs.org/ansi-color

我认为这可能是 github 项目:https://github.com/loopj/commonjs-ansi-color

无论如何,我无法继续,我们所有的构建都失败了,因为它们无法获取给定的依赖项。

我或许可以以某种方式使用 npm shrinkwrap,但这取决于 node_modules 中已经存在的模块,我目前缺少这些模块。

那么如何强制 npm 从不同的位置使用 ansi-color,或者忽略依赖关系?

不确定 npm 2,但您可以使用 beta npm 3 解决此问题。npm 3 具有平面 node_modules 目录。所以子模块可以位于顶层。阅读 Changelog.

缺少的模块可以直接从它们的 Github 存储库安装,作为项目中的顶级依赖项。如果 npm 在 node_modules 目录中找到具有相同版本的模块,它将不再在注册表中查找它。

安装 npm 3:

npm install -g npm@3-latest 

然后安装依赖项:

//install missing module from other location
npm install  https://github.com/loopj/commonjs-ansi-color.git --save-dev
npm install --save-dev brunch

看起来 ansi-color 已重新出现在 npm 注册表中(“https://registry.npmjs.org/ansi-color”已重新在线)