gpt4 book ai didi

node.js - npm --save-dev 不与 --prefix 一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 23:34:14 26 4
gpt4 key购买 nike

当我运行这个时:

npm install angular-mocks --save-dev

我在 ./node_modules 中获得了角度模拟,并在 ./package.json 中获得了对角度模拟的引用

当我运行这个时:

npm install angular-mocks --prefix ./Content/libs

我在 ./Content/libs/node_modules 中得到了角度模拟

当我运行这个时:

npm install angular-mocks --save-dev --prefix ./Content/libs

我在 ./Content/libs/nod_modules 中得到了 angular-mocks,但在 ./package.json 中没有引用 anguar-mocks

当我使用 --prefix 时,为什么 npm 不将引用保存在 package.json 中?

最佳答案

Why is npm not saving the reference in package.json when I use --prefix?

它是(或者至少会这样做),但它期望 package.json 位于它放置 node_modules 文件夹的父文件夹中。

在您的情况下,这将是 ./Content/libs

尝试一下:

mkdir -p ~/test/Content/libs
cd ~/test/Content/libs
npm init (accept defaults)
cd ~/test
npm install angular-mocks --save-dev --prefix ./Content/libs
cat ~/test/Content/libs/package.json

package.json:

{
"name": "libs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"angular-mocks": "^1.4.8"
}
}

如您所见,Angular-Mocks 已保存到 devDependencies 中。

此 SO 线程包含有关将本地包安装到自定义位置的更多详细信息:npm local install package to custom location

关于node.js - npm --save-dev 不与 --prefix 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com