使用 npm,您可以使用指向包含 Node 模块的 gzip 压缩包的 URL 来声明依赖项。我通过在 OSX 终端中运行 tar 命令来实现此功能。但我宁愿使用 git archive,以便输出不包含 .git 内容和存储库(node_modules)忽略的内容。
我像这样创建存档:
git archive master | gzip > ../archive.tar.gz
但是当我尝试使用 npm 安装它时(npm install archive.tar.gz 或将其放入 package.json),它失败并出现以下错误:
npm ERR! couldn't unpack /var/folders/gc/6rgb6g4x0n96nc1scbvv87040000gn/T/npm-1329949280846/1329949280846-0.19062370574101806/tmp.tgz to /var/folders/gc/6rgb6g4x0n96nc1scbvv87040000gn/T/npm-1329949280846/1329949280846-0.19062370574101806
npm ERR! Could not install: /javascript/archive.tar.gz
npm ERR! Error: ENOTDIR, not a directory '/var/folders/gc/6rgb6g4x0n96nc1scbvv87040000gn/T/npm-1329949280846/1329949280846-0.19062370574101806/package/package.json'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Darwin 11.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "/javascript/archive.tar.gz"
npm ERR! cwd /Users/dave
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.0-beta-10
npm ERR! path /var/folders/gc/6rgb6g4x0n96nc1scbvv87040000gn/T/npm-1329949280846/1329949280846-0.19062370574101806/package/package.json
npm ERR! code ENOTDIR
npm ERR! message ENOTDIR, not a directory '/var/folders/gc/6rgb6g4x0n96nc1scbvv87040000gn/T/npm-1329949280846/1329949280846-0.19062370574101806/package/package.json'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/dave/npm-debug.log
知道 git 存档和常规 tar 之间有什么不同,这会导致 npm 安装失败吗?
最佳答案
虽然存档的格式可能在这个问题中发挥作用(如评论中提到的 Borealid ),但我还会仔细检查这是否与 npm
必须处理的参数长度问题无关。
看这个issue on npm 5个月前,有了这个fix proposed (这是针对 Windows 的,但如果路径确实很长,仍然可能对您的环境产生影响)。
另请参阅issue 1951: "Can't unpack with tar (on Mac)" ,其中 tar
的版本与 npm
不兼容(如 issue 1511 一样,也在 Mac 上)。
关于git - 使用 git archive 作为 npm 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9404407/