nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

Cannot find module '@angular-devkit/core' #14673

Closed markgoho closed 1 year ago

markgoho commented 1 year ago

Current Behavior

running the build target fails with error:

 >  NX   Cannot find module '@angular-devkit/core'

   Require stack:
   - /workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js
   - /workspaces/enroll-fe/node_modules/nx/src/command-line/run.js
   - /workspaces/enroll-fe/node_modules/nx/bin/run-executor.js

Error: Cannot find module '@angular-devkit/core'
Require stack:
- /workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js
- /workspaces/enroll-fe/node_modules/nx/src/command-line/run.js
- /workspaces/enroll-fe/node_modules/nx/bin/run-executor.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at Module.require (/workspaces/enroll-fe/node_modules/nx/src/adapter/compat.js:37:40)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)

Expected Behavior

Builds doesn't break after upgrading workspace

GitHub Repo

https://github.com/ideacrew/enroll-fe

Steps to Reproduce

  1. switch to workspace-upgrade-15-6-2 branch
  2. run npx nx build slcsp-calculator
  3. (sorry I added the packages below as a workaround, so remove them and then...)
  4. get error

Nx Report

console
Node : 16.18.1
   OS   : linux x64
   npm  : 8.19.3

   nx : 15.6.2
   @nrwl/angular : 15.6.2
   @nrwl/cypress : 15.6.2
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.2
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.2
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.6.2
   @nrwl/js : 15.6.2
   @nrwl/linter : 15.6.2
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.6.2
   @nrwl/workspace : 15.6.2
   @nrwl/vite : Not Found
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @ngneat/transloco: 4.2.2
         @ngrx/component-store: 15.1.0
         @ngrx/effects: 15.1.0
         @ngrx/entity: 15.1.0
         @ngrx/router-store: 15.1.0
         @ngrx/store: 15.1.0
         @ngrx/schematics: 15.1.0
         @ngrx/store-devtools: 15.1.0

Failure Logs

console
 >  NX   Cannot find module '@angular-devkit/core'

   Require stack:
   - /workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js
   - /workspaces/enroll-fe/node_modules/nx/src/command-line/run.js
   - /workspaces/enroll-fe/node_modules/nx/bin/run-executor.js

Error: Cannot find module '@angular-devkit/core'
Require stack:
- /workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js
- /workspaces/enroll-fe/node_modules/nx/src/command-line/run.js
- /workspaces/enroll-fe/node_modules/nx/bin/run-executor.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at Module.require (/workspaces/enroll-fe/node_modules/nx/src/adapter/compat.js:37:40)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)

Additional Information

If I try to manually install the missing module with npm i @angular-devkit/core -D and try to build, I get a new error:

 >  NX   Cannot find module '@angular-devkit/architect'

   Require stack:
   - /workspaces/enroll-fe/node_modules/nx/src/adapter/ngcli-adapter.js
   - /workspaces/enroll-fe/node_modules/nx/src/command-line/run.js
   - /workspaces/enroll-fe/node_modules/nx/bin/run-executor.js
   Pass --verbose to see the stacktrace.

and I install that package via npm i @angular-devkit/architect -D the build succeeds!

gerardcastell commented 1 year ago

I got exactly the same problem when updating from Nx 14.8 to Nx 15

gerardcastell commented 1 year ago

I just found a solution, I realised that I had the "@nrwl/angular" and "nrwl/nx-cloud" packages in the "dependencies" section within the package.json instead of in the "devDependencies" dictionary. I have moved and run rm -rf node_modules && npm i and then the build worked! Hope it help you 🙌

markgoho commented 1 year ago

I did have @nrwl/angular in my dependencies array, and I've moved it, but I'm curious how it got there to begin with

leosvelperez commented 1 year ago

Thanks for reporting this!

This was fixed on https://github.com/nrwl/nx/pull/14723 and the change will be released in the upcoming 15.7.0 release.

I did have @nrwl/angular in my dependencies array, and I've moved it, but I'm curious how it got there to begin with

The @nrwl/angular plugin contains some runtime code (data persistence, module federation helpers, etc.) that workspaces can use. That's why by default the plugin is added to the dependencies entry, just in case the runtime code is being used. You're free to move it to devDependencies if you don't depend on it at runtime.

I'm going to close this issue since it has been addressed. Please keep an eye on the releases to get the fix.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.