angularcommand-line-interfacenrwl-nxnrwl

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. 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 ]

Solution

  • 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:

    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.