安装包时,是什么决定了 package.json 中依赖项的 ^ 版本运算符?

What determines the ^ version operator for dependencies in package.json when installing a package?

我在 package.json 中注意到某些版本在依赖版本中具有 ^ 运算符,例如:

"prettier": "^2.2.1",

但是有些包不使用这个运算符,例如:

"typescript": "4.1.3"

我知道运算符的含义,但我通过 npm install -D <package> 安装了这两个包并且没有自己修改 package.json 那么如何确定是否包含此运算符?

npm 的 save-prefix 设置会影响在 运行ning npm install -D <package> 时在 package.json 中设置的前缀 - 默认情况下它设置为插入符号 (^) .

所以是的,有些包有前缀 ^ 而有些没有。

也许您通过 npm-config 命令无意中 运行 npm config set save-prefix=''(即您将其设置为空)。

如果你 运行 npm config get save-prefix 而它没有打印 ^,那么你需要 运行 npm config delete save-prefix 恢复到默认值 ^