前言
NPM大家都熟,天天都在用。最近,NPM不断出现的下载出错 “npm ERR! Error: No compatible version found” ,已经影响到正常的开发工作,到了不得不解决的地步了。网上到处都是这个错误的问题,但解决问题的文章很难找到。我有必要来写一下。
目录
- NPM下载出错 No compatible version found
- 官方解决方案
- 其他解决方案
1. NPM下载出错 No compatible version found
最近,NPM不断出现的下载出错 “npm ERR! Error: No compatible version found” ,已经影响到了正常的开发工作,到了不得不解决的地步了。
我的系统环境
- Win7 64bit
- Node v0.10.5
- NPM 1.2.19
NPM的下载出错
npm ERR! Error: No compatible version found: [email protected]‘^1.2.0‘
npm ERR! Valid install targets:
npm ERR! ["0.1.0","0.2.1","0.2.2","1.0.0","1.1.0","1.2.0"]
npm ERR! at installTargetsError (D:\toolkit\nodejs\node_modules\npm\lib\cache.js:689:10)
npm ERR! at D:\toolkit\nodejs\node_modules\npm\lib\cache.js:611:10
npm ERR! at saved (D:\toolkit\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR! <[email protected]>
像这种类库管理本来不用动脑子的事情,一下子就会变得很麻烦了,小白程序员肯定是各种抓狂,网上所有的文章都解决不了自己的问题,对Nodejs瞬间失去信心….
我的项目中,只是要配置gulp包及相关插件的依赖下载,项目配置文件为 package.json。
{
"name": "nodejs-cnpm",
"version": "0.0.1",
"description": "cnpm",
"keywords": [
"cnpm"
],
"author": "Conan Zhang <[email protected]>",
"main": "cnpm",
"dependencies": {},
"devDependencies": {
"gulp": "^3.8.7",
"gulp-changed": "^1.0.0",
"gulp-concat": "^2.3.4",
"gulp-jshint": "^1.8.4",
"gulp-minify-css": "^0.3.7",
"gulp-ngmin": "^0.3.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.0",
"gulp-util": "^3.0.1"
}
}
无论怎么运行都是No compatible version found的错误。
~ npm install
npm WARN package.json [email protected] No readme data!
npm http GET https://registry.npmjs.org/gulp-changed
npm http GET https://registry.npmjs.org/gulp-concat
npm http GET https://registry.npmjs.org/gulp-ngmin
npm http GET https://registry.npmjs.org/gulp-uglify
npm http GET https://registry.npmjs.org/gulp-util
npm http GET https://registry.npmjs.org/gulp
npm http GET https://registry.npmjs.org/gulp-jshint
npm http GET https://registry.npmjs.org/gulp-minify-css
npm http GET https://registry.npmjs.org/gulp-rename
npm http 304 https://registry.npmjs.org/gulp-uglify
npm http 304 https://registry.npmjs.org/gulp-ngmin
npm ERR! Error: No compatible version found: [email protected]‘^1.0.0‘
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.3","0.0.4","0.1.0","0.2.0","0.2.1","0.3.0","0.3.1","0.3.2","1.0.0-0","1.0.0"]
npm ERR! at installTargetsError (D:\toolkit\nodejs\node_modules\npm\lib\cache.js:689:10)
npm ERR! at D:\toolkit\nodejs\node_modules\npm\lib\cache.js:611:10
npm ERR! at saved (D:\toolkit\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\get.js:138:7)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "D:\\toolkit\\nodejs\\\\node.exe" "D:\\toolkit\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd D:\workspace\javascript\nodejs-cnpm
npm ERR! node -v v0.10.5
npm ERR! npm -v 1.2.19
npm http 304 https://registry.npmjs.org/gulp-concat
npm http 304 https://registry.npmjs.org/gulp-jshint
npm http 304 https://registry.npmjs.org/gulp-minify-css
npm http 304 https://registry.npmjs.org/gulp-changed
npm http 304 https://registry.npmjs.org/gulp-util
npm http 304 https://registry.npmjs.org/gulp
npm http 304 https://registry.npmjs.org/gulp-rename
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! D:\workspace\javascript\nodejs-cnpm\npm-debug.log
npm ERR! not ok code 0
2. 官方解决方案
查看NPM官方的说明Issue列表( https://github.com/npm/npm/issues/4984 ),这个问题已经被解决,但解决办法确实很不友好。
如果在Linux系统中,通过一条命令更新npm可以解决。
npm install -g npm
在Window环境中,必须升级NPM到1.4.10以上的版本,我重新安装了node-v0.10.31-x64.msi,对应的NPM为1.4.23,再此运行npm install命令,依赖包下载运行正常。
升级后的系统环境
- Win7 64bit
- Node 0.10.31
- NPM 1.4.23
下载依赖包,运行正常。
~ npm install
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm WARN deprecated [email protected]: Deprecated in favor of gulp-ng-annotate: https://github.com/Kagami/gulp-ng-annotat
e - Reasoning: https://github.com/btford/ngmin/issues/93
[email protected] node_modules\gulp-rename
[email protected] node_modules\gulp-changed
└── [email protected] ([email protected], [email protected])
[email protected] node_modules\gulp-util
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
[email protected] node_modules\gulp-uglify
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected])
[email protected] node_modules\gulp-minify-css
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] (lodash._reinterpol[email protected], [email protected], [email protected], [email protected], [email protected],[email protected], [email protected])
[email protected] node_modules\gulp-concat
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
[email protected] node_modules\gulp-ngmin
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected],[email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
[email protected] node_modules\gulp
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
[email protected] node_modules\gulp-jshint
├── [email protected]
├── [email protected] ([email protected])
├── minimatch[email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
向这种强制性的升级,对于开发者来说是很不友好的、很难接受的。一个稳定运行的应用,只是为了改动一个小功能,被这种霸王的条件强制升级,有可能应用的整个环境都被破坏了,其他的很多包也要跟着升级,代价很大啊!
3. 其他解决方案
我在测试中发现了,除了强制升级NPM以外,还有一种解决方案,就是利用CNPM代替NPM来进行依赖管理,也能够正常地下载依赖包。
CNPM 是一个Nodejs的库,致力于打造私有的 NPM 注册服务。当然,除了私有库功能以外,CNPM官网还提供了NPM同步的服务。CNPM的配置及使用,将在下一篇文章中介绍,请参考文章CNPM搭建私有的NPM服务。让我们远离NPM包下载的错误吧,专心写好程序才是重点!
转载请注明出处:
http://blog.fens.me/nodejs-npm-no-compatible-version