npm安装失败,具有多层本地依赖性

时间:2015-02-09 20:32:58

标签: npm

如果我依赖于本身依赖于另一个本地包的本地包,那么

npm install似乎不起作用。我正在使用npm版本2.5.1。

这就是我所拥有的:

/ src / modules / moduleA的package.json:

{
  "name": "moduleA",
  "version": "0.0.1",
  ...
  "dependencies": {
    "bluebird": "^2.9.1",
    "nodemailer": "^1.3.0"
  }
}

/ src / modules / moduleB的package.json:

{
  "name": "moduleB",
  "version": "1.0.0",
  ...
  "dependencies": {
    "nconf": "~0.6.7",
    "moduleA": "../moduleA"
  }
}

package.json for / src / apps / coolApp:

{
  "name": "coolApp",
  "version": "1.0.0",
  ...
  "dependencies": {
    "mysql": "~2.4.2",
    "request": "~2.40.0",
    "cheerio": "~0.17.0",
    "async": "~0.9.0",
    "expand-url": "0.1.3",
    "moduleB": "../../modules/moduleB"
  }
}

现在,如果我尝试npm install

cd /src/modules/moduleA
npm install
    [success, yay!]

cd /src/modules/moduleB
npm install
    [success, yay!]

cd /src/apps/coolApp
npm install
    npm ERR! addLocal Could not install /src/node/apps/moduleA
    npm ERR! enoent ENOENT, open '/src/node/apps/moduleA'
    npm ERR! enoent This is most likely not a problem with npm itself
    npm ERR! enoent and is related to npm not being able to find a file.
[oh no!]

出于某种原因,npm正在尝试为coolApp安装moduleA,即使它不需要直接安装,而且它正在使用相对路径字符串,因为它在moduleB的package.json文件中字面指定,即使这对coolApp无效,因为它位于相对不同的位置。

1 个答案:

答案 0 :(得分:3)

我发现如果你在路径之前用“file:”指定本地模块,一切正常。耶

像这样:

"moduleB": "file:../../modules/moduleB"