nx: New Workspace + add Angular = Could not find module "@nrwl/workspace"

Expected Behavior

Creating new workspace via npm, add Angular tooling, and generate Angular app should use latest version and not crash.

This relates to ticket #1497, but is not the same

Current Behavior

Crashes at end of ng add @nrwl/angular

Failure Information

…error received during ng add @nrwl/angular install:

Installed packages for tooling via npm.
Could not find module "@nrwl/workspace" from "...\myworkspace".
Error: Could not find module "@nrwl/workspace" from "...\myworkspace".
    at Object.resolve (...\myworkspace\node_modules\@angular-devkit\core\node\resolve.js:141:11)
    at NodeModulesEngineHost._resolvePackageJson (...\myworkspace\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:28:21)
    at NodeModulesEngineHost._resolveCollectionPath (...\myworkspace\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:69:40)
    at NodeModulesEngineHost.createCollectionDescription (...\myworkspace\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:111:27)
    at SchematicEngine._createCollectionDescription (...\myworkspace\node_modules\@angular-devkit\schematics\src\engine\engine.js:147:40)
    at SchematicEngine._createCollectionDescription (...\myworkspace\node_modules\@angular-devkit\schematics\src\engine\engine.js:158:48)
    at SchematicEngine.createCollection (...\myworkspace\node_modules\@angular-devkit\schematics\src\engine\engine.js:140:43)
    at AddCommand.getCollection (...\myworkspace\node_modules\@angular\cli\models\schematic-command.js:123:35)
    at AddCommand.runSchematic (...\myworkspace\node_modules\@angular\cli\models\schematic-command.js:262:50)
    at AddCommand.executeSchematic (...\myworkspace\node_modules\@angular\cli\commands\add-impl.js:134:31)
    at AddCommand.run (...\myworkspace\node_modules\@angular\cli\commands\add-impl.js:105:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce

  1. npm init nx-workspace myworkspace
  2. From new workspace folder… ng add @nrwl/angular

Context

relevant information about my setup:

  • version of Nx used: latest provided by npm init nx-workspace myworkspace - 7.6.2
  • version of Angular CLI used: defined by nx in workspace - 7.3.1, but my global is 8.0.3
  • Node: 10.14.0
  • OS: win32 x64
  • I’ve created a demo repo for you to see what was created by running the above commands on my Windows laptop.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 29 (1 by maintainers)

Most upvoted comments

This keeps haunting me. I’ve created a brand new workspace with the latest nx as far as I know and I keep getting this error. Is there any fix?

I have still this error. Installed nx for the first time with:

npm install -g @nrwl/cli

source: https://nx.dev/web/guides/cli

After that I try whats @vsavkin write: https://github.com/nrwl/nx/issues/1306#issuecomment-495283429

npx create-nx-workspace@latest my-ui-admin --preset=empty
ng g app angularapp --e2e-test-runner=proctractor

Because I want a app with protractor.

After last command I get the error:

An unhandled exception occurred: Schematic "app" not found in collection "@nrwl/workspace".

I tried it also with:

npm init nx-workspace myworkspace

-> empty workspace -> angular-cli

and after that the ng g add command, but with same result.

My System infos:

Mac: 10.15.2
Nx Version: 8.11.2
Angular CLI: 8.3.14
Node: 10.18.0
OS: darwin x64

rough start 😉

Update: After reading: https://github.com/nrwl/nx I get it work:

npm install --save-dev @nrwl/angular
nx g @nrwl/angular:app myapp --e2e-test-runner=proctractor

@michael-golden I’m using Nx with Angular, and I fixed it doing :

nx update --all --force

❯ nx generate @nrwl/angular:application appName works for me.

Found workaround: npm i -g @nrwl/workspace - after installing workspace globally
npx create-nx-workspace myworkspace works.

ng add @nrwl/angular fixed it for me.

having same issue as @ph55

It looks like an older version of Nx was used.

Please use npm init nx-workspace@latest myworkspace to make sure you get the latest version.

You only need to add @nrwl/angular when using Nx 8+

hey guys @sergidt , @ph55 yep… had to install @nrwl/workspace first