前言

NPM大家都熟,天天都在用。最近,NPM不断出现的下载出错 “npm ERR! Error: No compatible version found” ,已经影响到正常的开发工作,到了不得不解决的地步了。网上到处都是这个错误的问题,但解决问题的文章很难找到。我有必要来写一下。

目录

  1. NPM下载出错 No compatible version found
  2. 官方解决方案
  3. 其他解决方案

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: gulp-rename@'^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! <npm-@googlegroups.com>

像这种类库管理本来不用动脑子的事情,一下子就会变得很麻烦了,小白程序员肯定是各种抓狂,网上所有的文章都解决不了自己的问题,对Nodejs瞬间失去信心….

我的项目中,只是要配置gulp包及相关插件的依赖下载,项目配置文件为 package.json。


{
"name": "nodejs-cnpm",
"version": "0.0.1",
"description": "cnpm",
"keywords": [
"cnpm"
],
"author": "Conan Zhang <bsspirit@gmail.com>",
"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 nodejs-cnpm@0.0.1 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: gulp-uglify@'^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! <npm-@googlegroups.com> 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 nodejs-cnpm@0.0.1 No repository field.
npm WARN package.json nodejs-cnpm@0.0.1 No README data
npm WARN deprecated gulp-ngmin@0.3.0: Deprecated in favor of gulp-ng-annotate: https://github.com/Kagami/gulp-ng-annotat
e - Reasoning: https://github.com/btford/ngmin/issues/93
gulp-rename@1.2.0 node_modules\gulp-rename gulp-changed@1.0.0 node_modules\gulp-changed
└── through2@0.6.1 (xtend@4.0.0, readable-stream@1.0.31) gulp-util@3.0.1 node_modules\gulp-util
├── lodash._reinterpolate@2.4.1
├── dateformat@1.0.8-1.2.3
├── minimist@1.1.0
├── lodash@2.4.1
├── chalk@0.5.1 (escape-string-regexp@1.0.1, ansi-styles@1.1.0, supports-color@0.2.0, strip-ansi@0.3.0, has-ansi@0.1.0)
├── through2@0.6.1 (xtend@4.0.0, readable-stream@1.0.31)
├── multipipe@0.1.1 (duplexer2@0.0.2)
├── vinyl@0.4.2 (clone-stats@0.0.1)
└── lodash.template@2.4.1 (lodash.values@2.4.1, lodash.defaults@2.4.1, lodash._escapestringchar@2.4.1, lodash.templatesettings@2.4.1, lodash.keys@2.4.1, lodash.escape@2.4.1) gulp-uglify@1.0.0 node_modules\gulp-uglify
├── deepmerge@0.2.7
├── vinyl-sourcemaps-apply@0.1.1 (source-map@0.1.38)
├── through2@0.6.1 (xtend@4.0.0, readable-stream@1.0.31)
└── uglify-js@2.4.15 (uglify-to-browserify@1.0.2, async@0.2.10, optimist@0.3.7, source-map@0.1.34) gulp-minify-css@0.3.7 node_modules\gulp-minify-css
├── memory-cache@0.0.5
├── bufferstreams@0.0.1
├── clean-css@2.2.15 (commander@2.2.0)
├── through2@0.5.1 (xtend@3.0.0, readable-stream@1.0.31)
└── gulp-util@2.2.20 (lodash._reinterpolate@2.4.1, dateformat@1.0.8-1.2.3, minimist@0.2.0, chalk@0.5.1, vinyl@0.2.3,lodash.template@2.4.1, multipipe@0.1.1) gulp-concat@2.3.4 node_modules\gulp-concat
├── through@2.3.4
├── concat-with-sourcemaps@0.1.3 (source-map@0.1.38)
└── gulp-util@2.2.20 (dateformat@1.0.8-1.2.3, lodash._reinterpolate@2.4.1, minimist@0.2.0, chalk@0.5.1, multipipe@0.1.1, vinyl@0.2.3, lodash.template@2.4.1, through2@0.5.1) gulp-ngmin@0.3.0 node_modules\gulp-ngmin
├── gulp-util@2.2.20 (lodash._reinterpolate@2.4.1, dateformat@1.0.8-1.2.3, minimist@0.2.0, chalk@0.5.1, vinyl@0.2.3,through2@0.5.1, lodash.template@2.4.1, multipipe@0.1.1)
├── through2@0.4.2 (xtend@2.1.2, readable-stream@1.0.31)
└── ngmin@0.5.0 (astral@0.1.0, clone@0.1.18, ngmin-dynamic@0.0.1, astral-angular-annotate@0.0.2, commander@1.1.1, esprima@1.0.4, escodegen@0.0.28) gulp@3.8.7 node_modules\gulp
├── tildify@0.2.0
├── interpret@0.3.6
├── pretty-hrtime@0.2.1
├── deprecated@0.0.1
├── archy@0.0.2
├── minimist@0.2.0
├── semver@3.0.1
├── orchestrator@0.3.7 (sequencify@0.0.7, stream-consume@0.1.0, end-of-stream@0.1.5)
├── chalk@0.5.1 (escape-string-regexp@1.0.1, ansi-styles@1.1.0, supports-color@0.2.0, strip-ansi@0.3.0, has-ansi@0.1.0)
├── liftoff@0.12.1 (extend@1.3.0, resolve@0.7.4, findup-sync@0.1.3)
└── vinyl-fs@0.3.7 (graceful-fs@3.0.2, strip-bom@1.0.0, mkdirp@0.5.0, lodash@2.4.1, vinyl@0.4.2, through2@0.6.1, glob-stream@3.1.15, glob-watcher@0.0.6) gulp-jshint@1.8.4 node_modules\gulp-jshint
├── lodash@2.4.1
├── rcloader@0.1.2 (rcfinder@0.1.8)
├── minimatch@0.3.0 (sigmund@1.0.0, lru-cache@2.5.0)
├── through2@0.5.1 (xtend@3.0.0, readable-stream@1.0.31)
└── jshint@2.5.5 (strip-json-comments@0.1.3, underscore@1.6.0, exit@0.1.2, console-browserify@1.1.0, shelljs@0.3.0, cli@0.6.4, htmlparser2@3.7.3)

向这种强制性的升级,对于开发者来说是很不友好的、很难接受的。一个稳定运行的应用,只是为了改动一个小功能,被这种霸王的条件强制升级,有可能应用的整个环境都被破坏了,其他的很多包也要跟着升级,代价很大啊!

3. 其他解决方案

我在测试中发现了,除了强制升级NPM以外,还有一种解决方案,就是利用CNPM代替NPM来进行依赖管理,也能够正常地下载依赖包。

CNPM 是一个Nodejs的库,致力于打造私有的 NPM 注册服务。当然,除了私有库功能以外,CNPM官网还提供了NPM同步的服务。CNPM的配置及使用,将在下一篇文章中介绍,请参考文章CNPM搭建私有的NPM服务。让我们远离NPM包下载的错误吧,专心写好程序才是重点!

转载请注明出处:
http://blog.fens.me/nodejs-npm-no-compatible-version

NPM下载出错 No compatible version found的更多相关文章

  1. 解决 no compatible version found: ionic-native@^3.5.0

    npm ERR! Linux --generic npm ERR! argv "/usr/src/node-v6.10.3-linux-x64/bin/node" "/u ...

  2. homestead虚拟机,通过npm下载依赖包和解决运行gulp报错问题 yarn出错问题

    homestead虚拟机,通过npm下载依赖包和解决运行gulp报错问题 yarn出错问题 1. 在虚拟器运行 npm 下载依赖组件时报错: npm ERR! EPROTO: protocol err ...

  3. Node.js安装,多版本管理以及修改npm下载的镜像源

    注意:在操作之前建议先把整个文章看完,在决定要不要配置!!!!! 1.下载    地址:http://nodejs.cn/download/        根据系统对应版本下载文件 2.安装    下 ...

  4. 【stm32开发之HAL采坑记之:001使用ST-LINK下载出错问题】

    使用ST-LINK下载出错问题 开发环境:swstm32+stm32cubeMx+硬石F1开发板 联系方式:yexiaopeng1992@126.com 出现问题:在使用ST-linik下载时发现,在 ...

  5. 整合shiro出现【Correct the classpath of your application so that it contains a single, compatible version of org.quartz.Scheduler】

    跑的时候出现错误: Description: An attempt was made to call the method org.quartz.Scheduler.getListenerManage ...

  6. npm i 出错

    npm i npm ERR! code ECONNRESET npm ERR! errno ECONNRESET npm ERR! network request to https://registr ...

  7. 初识node.js(通过npm下载项目依赖的包的过程)

    一.初识node.js 简单的说Node.js 就是运行在服务器端的JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事 ...

  8. 修改npm下载模块的安装位置

    默认安装完node.js后会自己安装npm,通过npm下载全局模块默认安装到C:\Users\user\AppData\Roaming目录下,主要有两个文件夹:npm.npm-cache npm:下载 ...

  9. java.lang.IllegalStateException: Received message from unsupported version: [5.2.2] minimal compatible version is: [5.6.0]

    启动elasticsearch-6.2.2-Windows服务时报错: java.lang.IllegalStateException: Received message from unsupport ...

随机推荐

  1. WebVR

    WebVR 主要面向Web前端工程师,需要一定Javascript及three.js基础:本文主要分享内容为基于three.js开发WebVR思路及碰到的问题:有兴趣的同学,欢迎跟帖讨论. 目录:一. ...

  2. 为什么ELF文件的加载地址是0x8048000

    在一个进程的虚拟地址空间中,ELF文件是从0x8048000这个地址开始加载的,为什么会是这个地址? 回答:用命令ld --verbose可以看到0x08048000,ld的默认脚本用这个地址作为EL ...

  3. HTML5面试题-备

    万不可投机取巧.只求当时过关,非长久之计也!(感谢大神分享) 面试有几点需要注意: 面试题目: 根据你的等级和职位变化,入门级到专家级:范围↑.深度↑.方向↑. 题目类型: 技术视野.项目细节.理论知 ...

  4. TWRP-recovery中文界面安装方法[转]

    把下载到的ui.zip放入sdcard1/twrp文件夹.注意,是内置存储卡中.如没有上述文件夹,自行建立后通过文件管理器放入,不是卡刷.文件夹应如下所示:sdcard1(内置SD)  |  ┕--t ...

  5. vi使用入门指南

    一.Unix编辑器概述 编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件.Unix及其相似的ix操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编辑 ...

  6. android手机端保存xml数据

    1.前面写的这个不能继续插入数据,今天补上,当文件不存在的时候就创建,存在就直接往里面添加数据. 2.代码如下: <pre name="code" class="j ...

  7. PYTHON线程知识再研习E---条件变量同步Condition

    Python提供的Condition对象提供了对复杂线程同步问题的支持.Condition被称为条件变量,除了提供与Lock类似的 acquire和release方法外,还提供了wait和notify ...

  8. Cmake ,Out of Source Build

    Out of Source build呢,就是让Cmake产生的临时垃圾文件,不关乎于项目实际本身的文件放到一个目录里,一般我们把这个目录放在项目根目录(也可以认为是根CmakeLists.txt)下 ...

  9. Manage Spring Boot Logs with Elasticsearch, Logstash and Kibana

    下载地址:https://www.elastic.co/downloads When time comes to deploy a new project, one often overlooked ...

  10. Mysql unix_timestamp() FROM_UNIXTIME和DATE_FORMAT(date,format)

    mysql 中:UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date) 若无参数调用,则返回一个 Unix timestamp ('1970-01-01 00:00:00' GM ...