npm install 因多层本地依赖项而失败
npm install fails with multi-layered local dependencies
如果我依赖的本地包本身又依赖于另一个本地包,那么 npm install 似乎不起作用。我正在使用 npm 版本 2.5.1.
这是我拥有的:
package.json 对于 /src/modules/moduleA:
{
"name": "moduleA",
"version": "0.0.1",
...
"dependencies": {
"bluebird": "^2.9.1",
"nodemailer": "^1.3.0"
}
}
package.json 对于 /src/modules/moduleB:
{
"name": "moduleB",
"version": "1.0.0",
...
"dependencies": {
"nconf": "~0.6.7",
"moduleA": "../moduleA"
}
}
package.json 对于 /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,即使它不需要直接安装,而且它正在使用 package.json 中逐字指定的相对路径字符串moduleB 的文件,即使它对 coolApp 无效,因为它位于相对不同的位置。
我发现如果在路径前用 "file:" 指定本地模块,一切正常。耶
像这样:
"moduleB": "file:../../modules/moduleB"
如果我依赖的本地包本身又依赖于另一个本地包,那么 npm install 似乎不起作用。我正在使用 npm 版本 2.5.1.
这是我拥有的:
package.json 对于 /src/modules/moduleA:
{
"name": "moduleA",
"version": "0.0.1",
...
"dependencies": {
"bluebird": "^2.9.1",
"nodemailer": "^1.3.0"
}
}
package.json 对于 /src/modules/moduleB:
{
"name": "moduleB",
"version": "1.0.0",
...
"dependencies": {
"nconf": "~0.6.7",
"moduleA": "../moduleA"
}
}
package.json 对于 /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,即使它不需要直接安装,而且它正在使用 package.json 中逐字指定的相对路径字符串moduleB 的文件,即使它对 coolApp 无效,因为它位于相对不同的位置。
我发现如果在路径前用 "file:" 指定本地模块,一切正常。耶
像这样:
"moduleB": "file:../../modules/moduleB"