nrwl / nx-console

Nx Console is the user interface for Nx & Lerna.
https://nx.dev
MIT License
1.31k stars 210 forks source link

Nx console using ng instead of nx, and it doesn't work #1626

Closed mooragor closed 1 year ago

mooragor commented 1 year ago

Current Behavior

When I use the Nx console in VSCode to run 'lint' on my code, it generates the following:

 *  Executing task: npx ng lint frm-smoke 
Workspace config file cannot be loaded: C:\Users\xxx\workspaces\xxx\Nx\angular.json
Invalid format version detected - Expected:[ 1 ] Found: [ 2 ]
 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npx ng lint frm-smoke" terminated with exit code: 1. 

If run the same commands on the command line myself, but substitute 'nx' for 'ng', the command works.

PS C:\Users\xxx\workspaces\xxx\Nx> npx nx lint frm-smoke
> nx run frm-smoke:lint
Linting "frm-smoke"...
All files pass linting.
 >  NX   Successfully ran target lint for project frm-smoke (2s)

PS C:\Users\xxx\workspaces\xxx\Nx> npx ng lint frm-smoke
Workspace config file cannot be loaded: C:\Users\xxx\workspaces\xxx\Nx\angular.json
Invalid format version detected - Expected:[ 1 ] Found: [ 2 ]

The angular.json file in the Nx folder does say in it it's ' "version": 2 '

Could the ng that's being used somehow be at a different version from nx?

Environment

PS C:\Users\xxx\workspaces\xxx\Nx> npx nx report
 >  NX   Report complete - copy this into the issue template

   Node : 18.13.0
   OS   : win32 x64
   npm  : 8.19.3

   nx : 15.6.3
   @nrwl/angular : 15.6.3
   @nrwl/cypress : 15.6.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.6.3
   @nrwl/js : 15.6.3
   @nrwl/linter : 15.6.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.6.3
   @nrwl/web : Not Found
   @nrwl/webpack : 15.6.3
   @nrwl/workspace : 15.6.3
   @nrwl/vite : Not Found
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @fortawesome/angular-fontawesome: 0.12.0
         @ngrx/component-store: 15.0.0
         @ngrx/effects: 15.0.0
         @ngrx/entity: 15.0.0
         @ngrx/router-store: 15.0.0
         @ngrx/store: 15.0.0
         angular-auth-oidc-client: 15.0.3
         ngx-bootstrap: 10.2.1
         @ngrx/schematics: 15.0.0
         @ngrx/store-devtools: 15.0.0
         @storybook/angular: 6.5.15
         ng-mocks: 14.6.0
Cammisuli commented 1 year ago

Version 2 of the angular.json/workspace.json only works with the nx cli.

Do you still have the postinstall script that does decorate-angular-cli.js or something similar to that?

Because of the angular.json file in the workspace, we always default to use the ng command, and if the decorate-angular-cli script is used, the ng command basically becomes nx under the hood.

Cammisuli commented 1 year ago

You can try running the nx repair command to see if it fixes things. Or rename the angular.json file to workspace.json and don't use the ng command.

mooragor commented 1 year ago

There is a 'decorate-angular-cli.js' file in the NX folder. I can see something in that saying 'symlinkNgCLItoNxCLI();' I'm not sure if that was actually run at any stage in my environment - do you know how I would/should do that?

I tried 'npx nx repair' which looks like it added a schema to many of the project.json files, but it hasn't helped with ng being run. "$schema": "../../node_modules/nx/schemas/project-schema.json",

Cammisuli commented 1 year ago

the decorate-angular-cli.js script should be run in a postinstall in the package.json like this: https://github.com/nrwl/nx-examples/blob/187bbad0ac064257aa11d32dfe01d481f73c7ee6/package.json#L26

mooragor commented 1 year ago

It does look like that's in there. Maybe I've just mucked something up with the various 'npm i' and 'npm ci' I've run in the past.

"postinstall": "node tools/scripts/ngx-bootstrap-patch.js && node ./decorate-angular-cli.js && ngcc --properties es2020 browser module main && npm run update:publishable:deps",
mooragor commented 1 year ago

Tried running the decorate script manually and it says:

PS C:\Users\xxx\workspaces\xxx\Nx> node ./decorate-angular-cli.js Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed.

But it does look like @nrwl/workspace is installed - I can see the folder there under node_modules.

PS - thank you hugely for all this help - it is really really appreciated!

Cammisuli commented 1 year ago

Remove your node_modules folder and do npm install locally. Without any other flags

mooragor commented 1 year ago

Have tried that, it again whinged about @nrwl/workspace not being installed, so what I have done is just manually do the rename/link by replacing the ng commands with copies of the nx commands under node_modules/.bin. All now working!

Thank you ever so much for your assistance!