Nx控制台正在使用ng而不是nx作为命令的运行程序,我该如何更改它?

huangapple go评论70阅读模式
英文:

Nx console is using ng instead of nx as the runner for the commands, how can I change it?

问题

以下是翻译好的部分:

"The title is pretty self explanatory."
标题相当自明。

"There is a large project that has been built with nx a couple of years ago, where nx console works."
有一个大型项目是几年前使用nx构建的,其中nx控制台可用。

"however, when running the commands, it is attempting to run them doing npx ng... instead of npx nx..."
然而,在运行命令时,它试图运行npx ng...而不是npx nx...

"as a result, since we are using angular 14 and nx 14, most of the commands don't work (like creating a new component, or a new library, or running lint or tests) because my angular.json file is version 2 (instead of v1 as expected by Angular's ng CLI)"
因此,由于我们使用的是Angular 14和nx 14,大多数命令不起作用(例如创建新组件、新库或运行lint或测试),因为我的angular.json文件是版本2(而不是Angular的ng CLI所预期的v1)。

"The error I keep getting is: Invalid format version detected - Expected: 1 Found: 2 "
我一直遇到的错误是:检测到无效的格式版本 - 预期: 1 ,发现: 2

英文:

The title is pretty self explanatory.
There is a large project that has been built with nx a couple of years ago, where nx console works.
however, when running the commands, it is attempting to run them doing npx ng...
instead of npx nx...

as a result, since we are using angular 14 and nx 14, most of the commands don't work (like creating a new component, or a new library, or running lint or tests) because my angular.json file is version 2 (instead of v1 as expected by Angular's ng CLI)

The error I keep getting is

Invalid format version detected - Expected:[ 1 ] Found: [ 2 ]

答案1

得分: 1

我意识到默认情况下,NX 似乎在大多数生成器命令中使用 ng 命令运行器。在仔细阅读他们的文档后,我注意到 nx CLI 装饰了 ng,使得 nxng 可以互换使用。然后我记得不久前在清理 package.json 文件时,我从我的项目根目录中删除了 decorate-angular-cli.js 文件以及 postinstall 命令。供参考:如果你生成任何 Angular NX 项目,你会在项目文件夹的根目录中得到一个名为 decorate-angular-cli.js 的文件,以及一个在你的 package.json 文件中看起来像这样的 postinstall 脚本:"postinstall": "node ./decorate-angular-cli.js"。对我来说,恢复这个文件和 postinstall 命令起了作用。这并没有使 nx console 使用 nx 而不是 ng,而是使 ng 命令运行得就像它们是 nx 一样(因为实际上在运行 decorate-angular-cli.js 文件的内容后,nxng 确实可以互换使用)。编辑:感谢 @Andrew Allen 在你的评论中指引我朝正确的方向发展。 1: https://nx.dev/more-concepts/nx-and-angular 2: https://stackoverflow.com/users/4711754/andrew-allen

英文:

After trying to generate a demo project to post here and answer the comment posted in my question, I realized that by default NX seems to use the ng command runner for most of the generator commands.

Upon reading thoroughly their documentation, I fixated in the fact that the nx CLI decorates ng, making nx and ng interchangeable.

Then I remembered not long ago while cleaning up the package.json file, I removed the decorate-angular-cli.js file from the root of my project, along with the postinstall command.

For reference:

  • if you generate any angular nx project, you'll get a file named decorate-angular-cli.js in the root of your project folder, and a postinstall script in your package.json that loks like this:

    "postinstall": "node ./decorate-angular-cli.js"

So for me, restoring the file and the postinstall command did the trick.
It did not make nx console use nx instead of ng, but instead it made the ng commands run as if they were nx (bc nx and ng are in fact interchangeable, only after running the contents of the file decorate-angular-cli.js)

Edit: thx @Andrew Allen for pointing me in the right direction with your comment.

huangapple
  • 本文由 发表于 2023年3月20日 22:54:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75791851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定