Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Workspace + add Angular = Could not find module "@nrwl/workspace" #1499

Closed
tomwhite007 opened this issue Jun 18, 2019 · 29 comments
Closed
Assignees

Comments

@tomwhite007
Copy link

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.
@servrox
Copy link

servrox commented Jun 18, 2019

same problem, when running tslint:
Could not find custom rule directory: node_modules/@nrwl/workspace/src/tslint

I updated from "@nrwl/nx": "7.8.6" to "@nrwl/nx": "7.8.7".

@FrozenPandaz
Copy link
Collaborator

FrozenPandaz commented Jun 18, 2019

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+

@tomwhite007
Copy link
Author

@FrozenPandaz , thanks very much. That worked a treat. I'll use that for now.

Technically however, this is still a bug - as all your docs don't mention @latest. Would you mind leaving this issue open, so that I can remain subscribed and know when it has been patched?

@girish121003
Copy link

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 @FrozenPandaz i tried the command you mentioned. I still get the same error.

@tdekoekkoek
Copy link

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?

@brandonroberts
Copy link
Contributor

@tdekoekkoek will you provide some more information about your environment? Such as:

  • node/npm version
  • OS version
  • exact repro steps
  • a GitHub repo of your generated project that fails

@ph55
Copy link

ph55 commented Aug 3, 2019

Neither npx create-nx-workspace@latest myworkspace
nor npm init nx-workspace@latest myworkspace works:

image

@aIbarrab
Copy link

aIbarrab commented Aug 3, 2019

having same issue as @ph55

@sergidt
Copy link

sergidt commented Aug 3, 2019

I have the same issue I can't create a new workspace neither npm init nx-workspace@latest nor npx create-nx-workspace.

I am running from a windows machine and the latest node version 12.7.0

@ph55
Copy link

ph55 commented Aug 3, 2019

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

@aIbarrab
Copy link

aIbarrab commented Aug 3, 2019

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

@saleemmalikraja
Copy link

If you are trying to create work-space

  • To install Nx CLI --> npm install -g @nrwl/cli
  • To install Nx workspace --> npm i -g @nrwl/workspace
  • To install typescript --> npm i -g typescript
    (: Happy coding :)

@tomwhite007
Copy link
Author

tomwhite007 commented Sep 15, 2019

Thanks to @FrozenPandaz for the temporary advice:

Please use npm init nx-workspace@latest myworkspace

As of Nrwl Nx version 8.5 this is no longer an issue.
npm init nx-workspace myworkspace

Now works just fine.

Closing issue...

@peterhe2000
Copy link

For me, install nx cli globally works.
npm install -g @nrwl/cli

@svox1
Copy link

svox1 commented Jan 24, 2020

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:
#1306 (comment)

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

@dnlmelo
Copy link

dnlmelo commented Feb 6, 2020

Only if I install @nrwl/workspace locally, then it works. It's right? Why @nrwl/workspace not appear in docs?

@duard
Copy link

duard commented Mar 26, 2020

Similar error here, the applications run but I cant create any library

➜ nx g @nrwl/angular:lib --directory=ng models --dry-run

Cannot find module '@nrwl/workspace/src/utils/rules/workspace'

@michael-golden
Copy link

michael-golden commented Mar 26, 2020

I'm having the same issue as @duard

> nx g @nrwl/angular:app dev-admin-app --dry-run
Cannot find module '@nrwl/workspace/src/utils/rules/workspace'
Require stack:
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\angular\src\schematics\init\init.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\angular\src\schematics\application\application.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\tao\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\tao\node_modules\@angular-devkit\schematics\tools\index.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\tao\src\commands\generate.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\tao\index.js
- C:\Repos\pa\pa_service_api\node_modules\@nrwl\cli\bin\nx.js
- C:\Users\Gamer\AppData\Roaming\npm\node_modules\@nrwl\cli\lib\init-global.js
- C:\Users\Gamer\AppData\Roaming\npm\node_modules\@nrwl\cli\bin\nx.js

EDIT: Running npm install after updating to nrwl/nx 9.1.14 resolved this issue.

@duard
Copy link

duard commented Mar 26, 2020

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

nx update --all --force

@gqchishti
Copy link

ng add @nrwl/angular
fixed it for me.

@tomwhite007
Copy link
Author

@gqchishti
I had this problem again after selecting Empty Workspace when creating with latest Nx.
Your solution fixed it for me. Thanks.

@overlineink
Copy link

overlineink commented May 15, 2020

Reviving the same error! 👎

[error] Error: Could not find module "@nrwl/workspace" from ".../x-workspace".
    at Object.resolve (/home/x/node_modules/@angular-devkit/core/node/resolve.js:154:11)
    at NodeModulesEngineHost._resolvePackageJson (/home/x/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:28:21)
    at NodeModulesEngineHost._resolveCollectionPath (/home/x/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:69:40)
    at NodeModulesEngineHost.createCollectionDescription (/home/x/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:115:27)
    at SchematicEngine._createCollectionDescription (/home/x/node_modules/@angular-devkit/schematics/src/engine/engine.js:147:40)
    at SchematicEngine.createCollection (/home/x/node_modules/@angular-devkit/schematics/src/engine/engine.js:140:43)
    at NewCommand.getCollection (/home/x/node_modules/@angular/cli/models/schematic-command.js:128:35)
    at NewCommand.initialize (/home/x/node_modules/@angular/cli/models/schematic-command.js:44:37)
    at async NewCommand.validateAndRun (/home/x/node_modules/@angular/cli/models/command.js:124:9)
    at async Object.runCommand (/home/x/node_modules/@angular/cli/models/command-runner.js:186:24)

@LPCmedia
Copy link

I had the same issue. After removing a rogue package.json, package-lock and node_modules that contained an older version of @nrwl/workspace folder in a parent directory, of my current working directory, the command worked as expected.

sorry I don't have the exact details...as I cleaned up the files were gone.

@AshkanHovold
Copy link

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

This helped me move forward. Then I got another error saying module 'typescript' was not found. Did "npm i -g typescript" then tried "npx create-nx-workspace myworkspace" again and this time it worked! Thnx alot :)

@peternixey
Copy link

I happened to come across this project today and it looked like a fantastic way to speed up my builds. I got the same errors as many others are describing though.

Running npm install @nrwl/nx-cloud && ng g @nrwl/nx-cloud:init on a clean install resulted in:

An unhandled exception occurred: Cannot find module '@nrwl/workspace'
Require stack:
- /Users/pn/Code/intentional/angular/node_modules/@nrwl/nx-cloud/lib/schematics/init/init.js
- /Users/pn/Code/intentional/angular/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /Users/pn/Code/intentional/angular/node_modules/@angular-devkit/schematics/tools/index.js
- /Users/pn/Code/intentional/angular/node_modules/@angular/cli/utilities/json-schema.js
- /Users/pn/Code/intentional/angular/node_modules/@angular/cli/models/command-runner.js
- /Users/pn/Code/intentional/angular/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/private/var/folders/5y/vhs03j3r16nzq9770ch0000gn/T/ng-fgCosC/angular-errors.log" for further details.

After starting to dig deeper it seems that maybe the onboarding for https://nx.app/orgs assumes that you've already got a bunch of other things in play. I didn't have any of those though so would be great to have a few more cues on where to start.

Looking forward to the chance to actually use this as the videos look super promising.

@ghost
Copy link

ghost commented Jul 19, 2020

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

@oletrn
Copy link

oletrn commented Nov 28, 2022

Finally, I've managed to generate a project with Karma runner this way:

  1. npx create-nx-workspace --preset=empty --name=my-app
  2. cd my-app
  3. npm install @nrwl/angular
  4. nx generate @nrwl/angular:app foobar --style=scss --unitTestRunner=karma

@ancientlunatic
Copy link

ancientlunatic commented Dec 31, 2022

I have managed to resolve this issue by
First, install the required nrwl package
for angular install npm i @nrwl/angular
then add your app
npx nx generate @nrwl/angular:app your-app-name

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests