为什么 "npm install <directory>" 忽略 devDependencies?

Why does "npm install <directory>" ignore devDependencies?

我在目录 ~/dirA 中有以下 package.json:

{
  "name": "dirA",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "vue": "^2.1.8"
  },
  "devDependencies": {
    "vue-loader": "^10.0.2"
  }
}

然后我 cd 到 ~/dirB 和 运行 npm install ../dirA 以便在 dirB 中创建 node_modules 目录。

问题是它没有安装 devDependencies。我的 NODE_ENV 环境变量没有设置。

我刚得到这个输出:

[~/dirB]$ npm install ../dirA
/home/tbeadle/dirB
`-- dirA@1.0.0
  `-- vue@2.1.8

npm WARN enoent ENOENT: no such file or directory, open '/home/tbeadle/dirB/package.json'
npm WARN dirB No description
npm WARN dirB No repository field.
npm WARN dirB No README data
npm WARN dirB No license field.

我什至可以使用 npm install --only=dev ../dirB 并且它继续忽略我在 package.json.

中定义的 devDependencies

知道如何安装这些 devDependencies 吗?

npm install <directory>

没有做你想做的事。根据文档 here,

npm install :

Install a package that is sitting in a folder on the filesystem.

此外,正如控制台警告所建议的那样,npm 安装需要 运行,其中存在 package.json。 要从 dirB 安装到 dirA, 这样做:

cd dirB

mkdir -p ../dirA/node_modules

npm install --prefix path_to_folder_in_dirA

勾选这个Whosebug question