Cygwin上的NPM:意外的文件结束

我正在尝试在cygwin上使用NPM,但不断收到以下错误:

ERR! tar "-mvxpf" "-" "--no-same-owner" "-C" "/tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents/___package.npm" tar: Unexpected EOF in archive ERR! tar "-mvxpf" "-" "--no-same-owner" "-C" "/tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents/___package.npm" tar: Unexpected EOF in archive ERR! tar "-mvxpf" "-" "--no-same-owner" "-C" "/tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents/___package.npm" tar: Error is not recoverable: exiting now ERR! tar "-mvxpf" "-" "--no-same-owner" "-C" "/tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents/___package.npm" ERR! Failed unpacking /tmp/npm-1305893882865/1305893885765-0.008730818051844835/tmp.tgz ERR! couldn't unpack /tmp/npm-1305893882865/1305893885765-0.008730818051844835/tmp.tgz to /tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents verbose about to build /home/Tema/node_modules/express ERR! error installing express@2.3.5 Error: Failed tar "-mvxpf" "-" "--no-same-owner" "-C" "/tmp/npm-1305893882865/1305893885765-0.008730818051844835/contents/___package.npm" 

有几个build议我GOOGLE(npmcaching干净和rebaseall),但没有任何帮助。 那么,在Cygwin中有没有办法使用NPM?

  1. 吹tmp目录

     rm -R /tmp/* 
  2. 清除npm的caching

     npm cache clean 
  3. 退出当前的shell并启动一个ash或dash shell(从cygwin / bin中)

  4. 在ash(或破折号)shell中执行rebaseall命令。

     /bin/rebaseall -v 
  5. 退出并重新启动一个新的bash shell。

  6. 再次尝试你的npm命令。

     npm install <package> 

我经常自己也有同样的问题。

我不知道如何解决,但是我知道这个错误是不规则的。 如果您尝试再次安装npm软件包,则可能会起作用。 只要不断重试,最终就会奏效。

当它卡在100%的CPU,只要取消它(Ctrl + C),然后再试一次。 另外,在安装包装时不要切换到另一个窗口。

您也可以在node_modules文件夹中使用wget和tar手动安装软件包。

尝试使用此命令删除临时文件:

 $ rm /tmp/npm-* 

然后再次安装。 为我工作。

/usr/local/lib/node_modules/npm/lib/utils/tar.js的小补丁

 --- tar.js.old 2011-07-15 15:23:09.205440100 +0700 +++ tar.js 2011-07-15 15:25:58.327113300 +0700 @@ -20,6 +20,7 @@ , relativize = require("./relativize") , cache = require("../cache") , excludes = require("./excludes") + , child_process = require("child_process"); exports.pack = pack exports.unpack = unpack @@ -168,13 +169,17 @@ //console.error(npm.config.get("gzipbin")+" --decompress --stdout " // +tarball+" | "+npm.config.get("tar")+" -mvxpf - -o -C " // +tmp) - pipe( spawn( npm.config.get("gzipbin") - , ["--decompress", "--stdout", tarball] - , process.env, false ) - , spawn( npm.config.get("tar") - , ["-mvxpf", "-", "-o", "-C", tmp] - , process.env, false ) - , function (er) { + // pipe( spawn( npm.config.get("gzipbin") + // , ["--decompress", "--stdout", tarball] + // , process.env, false ) + // , spawn( npm.config.get("tar") + // , ["-mvxpf", "-", "-o", "-C", tmp] + // , process.env, false ) + // , function (er) { + + child_process.exec(npm.config.get("gzipbin")+" --decompress --stdout " + +tarball+" | "+npm.config.get("tar")+" -mvxpf - --no-same-owner -C " +tmp + , function (er, stdout, stderr) { // if we're not doing ownership management, // then we're done now. if (er) return log.er(cb, 

如果发生这种情况,请尝试从.npm目录(可能位于主目录:〜/ .npm)中删除部分提取的模块,然后重试(两次或更多)。