gpt4 book ai didi

angular - 命令 ncu -u 到底是做什么的?

转载 作者:行者123 更新时间:2023-12-04 12:44:04 31 4
gpt4 key购买 nike

我一直在尝试将 Visual Studio 中的 angular 项目更新为特定版本的 angular。

我在关注 this tutorial我做了一些不同的事情,因为在本教程中,我获得了最新的 angular 版本,我特别想要 angular 的第 6 版。

为此,我确实运行了 npm install -g @angular/cli@6.2.9而不是教程一( npm install -g npm-check-updates )

在我运行了 ncu -u 之后无论如何,就像教程一样。

最后我还是得到了版本 7 的 package.json,这不是我想要的。

我知道 ncu意味着 npm-check-updates , 熟悉 -g这是全局安装。究竟是做什么的ncu -u确实如此,是更新了吗?

所以它忽略了我的 6 版本并继续使用最后一个?

我应该在这里做什么?我想查看我的包 json 上的更改,但是对于 6 而不是 7,但是这个命令是针对 7 的。

就像教程中的图像一样,您可以在命令行/PowerShell 中看到前后(我在管理员中使用了 PowerShell,如教程所述)。

我试过用这个
https://update.angular.io/

这仍然让我使用了第 7 版......而不是我在下拉列表中选择的 6.1。
看图

enter image description here

和我的 package.json 现在
enter image description here

最佳答案

正如 ncu 包 description 中所述

ncu -u upgrades your package.json dependencies to the latest versions, ignoring specified versions.

npm-check-updates maintains your existing semantic versioning policies, i.e., it will upgrade "express": "^4.0.0" to "express": "^5.0.0".

It only modifies your package.json file. Run npm install to update your installed packages and package-lock.json.



运行 ncu -u 后,您可能会收到另一个错误,如下所示:

There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

"babel-eslint": "10.0.1"

Don't try to install it manually: your package manager does it automatically. However, a different version of babel-eslint was detected higher up in the tree:

..ClientApp\node_modules\babel-eslint (version: 10.0.2)



对于初学者来说,node.js 中的依赖 hell 非常令人困惑,当修复一个错误时,你会得到另一个错误,然后另一个等等。

但是 当您开始仔细阅读每个错误和提示时 你很快就会知道问题是什么以及如何解决它。

所以执行后报错
ncu -u 

讲述依赖问题,即您的 package.json 现在包含最新版本,而某些包也可能依赖于某些包但不依赖于最新版本。

例如。最新版 react 脚本 包(目前@3.0.1 依赖于@10.0.1 的 babel-eslint)

但是目前最新的 babel-eslint 已经是@10.0.2。

ncu -u 命令 将最新的 babel-eslint@10.0.2 放入你的 package.json 文件中。

要解决此问题,您需要按照完整错误文本中提到的步骤(更长)或手动将 babel-eslint 版本降级到“10.0.1”。
 npm i babel-eslint@10.0.1

您可能会发现列出其他引用冲突包的包很有用
npm ls [conflicting_package]

npm ls babel-eslint

+-- babel-eslint@10.0.2 - explicit dependency in your package.json on babel-eslint.
`-- react-scripts@3.0.1 - explicit dependency in your package.json on react-scripts.
`-- babel-eslint@10.0.1 - implicit dependency with different version

关于angular - 命令 ncu -u 到底是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54364751/

31 4 0