【问题标题】:npm install is so fragile on windowsnpm install 在 Windows 上是如此脆弱
【发布时间】:2015-06-08 14:11:16
【问题描述】:

我有一个使用 grunt build 的项目。这是我的 packages.json。

...
"devDependencies": {
  "grunt": "^0.4.4",
  "grunt-autoprefixer": "^0.7.3",
  "grunt-coffeelint": "0.0.10",
  "grunt-concurrent": "^0.5.0",
  "grunt-connect-proxy": "^0.1.10",
  "grunt-contrib-clean": "^0.5.0",
  "grunt-contrib-concat": "^0.4.0",
  "grunt-contrib-connect": "^0.7.1",
  "grunt-contrib-copy": "^0.5.0",
  "grunt-contrib-csslint": "^0.2.0",
  "grunt-contrib-cssmin": "^0.9.0",
  "grunt-contrib-jshint": "^0.10.0",
  "grunt-contrib-less": "^0.11.0",
  "grunt-contrib-requirejs": "^0.4.4",
  "grunt-contrib-stylus": "^0.15.1",
  "grunt-contrib-uglify": "^0.4.0",
  "grunt-contrib-watch": "^0.6.1",
  "grunt-modernizr": "^0.5.2",
  "grunt-newer": "^0.7.0",
  "jshint-stylish": "^0.2.0",
  "load-grunt-tasks": "^0.4.0",
  "rjs-build-analysis": "0.0.3",
  "time-grunt": "^0.3.1"
},
...

我正在运行 npm 1.4.13 和节点 v0.10.28

当我运行 clean npm install 时,总会出现一些随机错误。而且每次都是不同的模块。如果错误来自缓存文件夹,那么我必须运行npm cache clean,或者如果错误在node_modules 文件夹中,则删除node_modules。然后我必须重试几次才能绕过错误。我尝试了 windows 8、windows 7 和 windows server 2008。这是错误日志之一。

C:\src>npm install
npm ERR! unpack Could not read data for sigmund@1.0.0
npm ERR! Error: ENOENT, chmod 'C:\src\node_modules\l
oad-grunt-tasks\node_modules\multimatch\node_modules\minimatch\node_modules\lru-
cache\CONTRIBUTORS'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\no
dejs\\\\node.exe" "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\n
odejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\src
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.13
npm ERR! path C:\src\node_modules\load-grunt-tasks\n
ode_modules\multimatch\node_modules\minimatch\node_modules\lru-cache\CONTRIBUTOR
S
npm ERR! fstream_path C:\src\node_modules\load-grunt
-tasks\node_modules\multimatch\node_modules\minimatch\node_modules\lru-cache\CON
TRIBUTORS
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! fstream_finish_call chmod
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:\src\packages\Ncapsulate.Node.0.10.28\no
dejs\node_modules\fstream\lib\writer.js:305:19
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: C:\Users\tim\AppData\Roaming\npm-cache\sigmund\1.0.0\package\pack
age.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\no
dejs\\\\node.exe" "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\n
odejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\src
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.13
npm ERR! file C:\Users\tim\AppData\Roaming\npm-cache\sigmund\1.0.0\package\packa
ge.json
npm ERR! code EJSONPARSE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\src\npm-debug.log
npm ERR! not ok code 0

有时它只是无法从注册表中获取模块。例如:

npm WARN package.json rjs-build-analysis@0.0.3 No repository field.
npm ERR! Error: failed to fetch from registry: lodash
npm ERR!     at RegClient.<anonymous> (C:\src\packages\Ncapsulate
.Node.0.10.28\nodejs\node_modules\npm-registry-client\lib\get.js:133:18)
npm ERR!     at cb (C:\src\packages\Ncapsulate.Node.0.10.28\nodej
s\node_modules\npm-registry-client\lib\request.js:32:9)
npm ERR!     at RegClient.<anonymous> (C:\src\packages\Ncapsulate
.Node.0.10.28\nodejs\node_modules\npm-registry-client\lib\request.js:107:16)
npm ERR!     at cb (C:\src\packages\Ncapsulate.Node.0.10.28\nodej
s\node_modules\npm-registry-client\lib\request.js:132:9)
npm ERR!     at RegClient.<anonymous> (C:\src\packages\Ncapsulate
.Node.0.10.28\nodejs\node_modules\npm-registry-client\lib\request.js:286:12)
npm ERR!     at Request._callback (C:\src\packages\Ncapsulate.Nod
e.0.10.28\nodejs\node_modules\npm-registry-client\lib\request.js:212:65)
npm ERR!     at Request.self.callback (C:\src\packages\Ncapsulate
.Node.0.10.28\nodejs\node_modules\request\request.js:123:22)
npm ERR!     at Request.EventEmitter.emit (events.js:98:17)
npm ERR!     at Request.<anonymous> (C:\src\packages\Ncapsulate.N
ode.0.10.28\nodejs\node_modules\request\request.js:893:14)
npm ERR!     at Request.EventEmitter.emit (events.js:117:20)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\no
dejs\\\\node.exe" "C:\\src\\packages\\Ncapsulate.Node.0.10.28\\n
odejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\src\npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.13
npm ERR! registry error parsing json
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\src\npm-debug.log
npm ERR! not ok code 0

我认为远程 npm 注册表不稳定,所以我设置了一个本地 npm 注册表镜像。但错误仍然发生。我不知道为什么 npm 在 windows 上那么不稳定。

【问题讨论】:

    标签: windows node.js npm


    【解决方案1】:

    npm 错误!注册表解析json出错

    相关模块的 package.json 文件丢失或存在语法错误

    npm 错误!错误:无法从注册表中获取:lodash

    有问题的模块不在注册表中

    npm 错误! cwd C:\src

    相关路径不存在

    npm 错误!错误:ENOENT,chmod 'C:\src\node_modules\l

    无权修改相关路径

    验证安装过程:

    • 您是否以管理员身份安装,然后以普通用户身份运行 npm?
    • 您是否将 nodeJS 安装到受保护的目录中?
    • 您的 PATH 设置是否正确?

    参考文献

    【讨论】:

    • package.json 未完全下载,因此语法错误。 Windows 没有权限问题。重试有时有效。 PATH设置好了,经过多次尝试,安装成功。
    猜你喜欢
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 2014-08-13
    相关资源
    最近更新 更多