我npm ERR! invalid
尝试的时候会遇到错误,npm ls
或者npm install
看起来npm错误地认为对等版本有不兼容的版本.一个很好的例子(我一次得到几个):
npm WARN unmet dependency /MYLOCALPROJECTDIRECTORY/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle requires image-type@'^0.1.1' but will load npm WARN unmet dependency /MYLOCALPROJECTDIRECTORY/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/image-type, npm WARN unmet dependency which is version 0.1.4
根据semver的规则,插入符"^"运算符应该与^0.1.1
版本的实际依赖性的要求匹配0.1.4
得很好.
我使用Homebrew(两个最新的稳定版)安装了Node v0.10.30和npm v1.4.23,运行OS X Mountain Lion.我很欣赏有关如何可靠地重现这一点的提示 - 上次我完全卸载/重新安装了Node和npm,相同的本地npm模块和所有内容,并且再次找不到错误.第二天回来工作,试图安装一些grunt插件,并再次遇到所有这些错误.
如果你碰巧重现它,我打赌你可以通过删除node_modules文件夹,清理缓存并重新安装来解决它:
rm -rf ./node_modules npm cache clean npm install
我知道这不是一个真正的答案,但我想这比卸载/重新安装node/npm要好.