通常情况下,我可以在谷歌上发现我面临的任何问题,但在这种情况下,我完全不知道该搜索什么。
我的父模块有两个依赖项:
"grunt-contrib-uglify": "~0.2.7""node-snapshot": "~0.3.22"然而,当node-snapshot也依赖于~0.2.7时,它并没有安装在node-snapshot的node_modules目录中。我的快照应用程序通过Travis自动部署到Heroku,因此:
"scripts": {
"test": "grunt test",
"start": "node example/server/default.js",
"postinstall": "node_modules/grunt-cli/bin/grunt build:production"
}在我的父模块(npm install node-snapshot)中安装它之后也会调用它,但是由于父模块和子模块都依赖grunt-contrib-uglify ~0.2.7而失败。
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
Warning: Task "uglify" not found. Use --force to continue.如果父模块依赖于不同的版本的grunt-contrib-uglify,那么node-snapshot成功地在其node_modules目录中安装了grunt-contrib-uglify,并且一切都是tickety。
我该如何解决这个问题?在我看来,所有的子模块都需要自己的安装,即使父模块有相同的模块,因为相对地,子模块(node-snapshot)无法找到它的依赖项之一。
发布于 2014-04-25 08:35:56
经过昨晚的研究,这显然是国家预防机制的一个众所周知的问题。有许多关于子模块依赖项的线程没有被安装,因为父模块已经满足了特定的依赖项。
特别是在GitHub上的以下线程提供了非常丰富的信息:https://github.com/npm/npm/issues/5001
目前还没有解决方案,但是的解决方案。
在我使用postinstall的特殊情况中,解决方法是添加一个带有--ignore-scripts标志的preinstall,这防止了递归调用scripts钩子。这使npm install能够隔离运行,从而安装所有依赖项,而不管父模块如何。
因此,我的package.json现在看起来几乎完全一样,但是使用preinstall钩子:
"scripts": {
"test": "grunt test",
"start": "node example/server/default.js",
"preinstall": "npm install --ignore-scripts",
"postinstall": "bower install; grunt build:production"
}发布于 2014-04-24 16:54:46
npm不安装重复的模块时,它可以帮助它。它也不需要运行脚本的路径。当你这样做时会发生什么:
"postinstall": "grunt build:production"https://stackoverflow.com/questions/23270157
复制相似问题