question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`npm run nx serve` fails after creating empty workspace, adding Angular plugin + creating new app

See original GitHub issue

Current Behavior

npm run nx serve fails after creating empty workspace, adding Angular plugin + creating a new application.

The message An unhandled exception occurred: Cannot find module 'webpack' is shown.

(Note that I am starting with an empty workspace rather than with the single Angular application template because I want to customize the options for the new Angular project as shown in the reproduction steps below.)

Expected Behavior

I expect npm run nx serve to start the Angular development server without errors.

Steps to Reproduce

On Windows 10 with NodeJS LTS 14.15.0:

  1. Open a new PowerShell window
  2. Run npx create-nx-workspace nxtest
  3. Choose the ‘empty’ template and the ‘Angular CLI’ option for the CLI
  4. Move into the new directory with cd nxtest
  5. Run npm install -D @nrwl/angular to install the Angular plugin
  6. Create a new Angular app as follows:
npm run nx g @nrwl/angular:app -- testapp  --e2e-test-runner=protractor --unit-test-runner=jest --strict --style=scss --routing --linter=eslint --enable-ivy
  1. Run npm run nx serve

Failure Logs

PS C:\Users\<username>\source\repos\nxtest> npm run nx serve

> nxtest@0.0.0 nx
> nx "serve"


> ng run testapp:serve
An unhandled exception occurred: Cannot find module 'webpack'
Require stack:
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\build-webpack\src\webpack\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\build-webpack\src\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\build-angular\src\dev-server\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\architect\node\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\models\architect-command.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\commands\run-impl.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular-devkit\schematics\tools\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\utilities\json-schema.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\models\command-runner.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\lib\cli\index.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@angular\cli\lib\init.js
- C:\Users\<username>\source\repos\nxtest\node_modules\@nrwl\cli\lib\run-cli.js
See "C:\Users\<USERNAME>~1\AppData\Local\Temp\ng-U7gsfD\angular-errors.log" for further details.
npm ERR! code 1
npm ERR! path C:\Users\<username>\source\repos\nxtest
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c "nx "serve""

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<username>\AppData\Local\npm-cache\_logs\2020-11-06T15_10_51_278Z-debug.log

Environment

Windows 10 Pro Version 10.0.19042 Build 19042 PowerShell version: 5.1.19041.610 NodeJS version: 14.15.0

nx report output:

  nx : Not Found
  @nrwl/angular : 10.3.2
  @nrwl/cli : 10.3.2
  @nrwl/cypress : 10.3.2
  @nrwl/eslint-plugin-nx : 10.3.2
  @nrwl/express : Not Found
  @nrwl/jest : 10.3.2
  @nrwl/linter : 10.3.2
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.3.2
  @nrwl/web : Not Found
  @nrwl/workspace : 10.3.2
  typescript : 4.0.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jonstellycommented, Apr 1, 2021

I’m getting the same issue. Following steps like mentioned above (which seem to be a short version of this migration overview guide).

I’m running this on Ubuntu 20.04 in WSL2. NPM version is 7.6.2.

After I get the error about missing webpack module, I can npm i --save-dev webpack to get webpack installed, then the nx serve seems to get a bit further but then errors out with:

Cannot read property 'add' of undefined
TypeError: Cannot read property 'add' of undefined
    at /home/me/code/my-framework/node_modules/@ngtools/webpack/src/ivy/plugin.js:164:86
    at Array.forEach (<anonymous>)
    at /home/me/code/my-framework/node_modules/@ngtools/webpack/src/ivy/plugin.js:164:33
    at SyncHook.eval [as call] (eval at create (/home/me/code/my-framework/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:9:1)
    at SyncHook.lazyCompileHook (/home/me/code/my-framework/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.newCompilation (/home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Compiler.js:630:30)
    at /home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Compiler.js:667:29
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/me/code/my-framework/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at AsyncSeriesHook.lazyCompileHook (/home/me/code/my-framework/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.compile (/home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Compiler.js:662:28)
    at /home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Watching.js:77:18
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/me/code/my-framework/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
    at AsyncSeriesHook.lazyCompileHook (/home/me/code/my-framework/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._go (/home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Watching.js:41:32)
    at /home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Watching.js:33:9
    at Compiler.readRecords (/home/me/code/my-framework/node_modules/@angular-devkit/build-angular/node_modules/webpack/lib/Compiler.js:529:11)

EDIT: This only happens using the empty template and steps in that migration guide. If I create a new angular workspace everything works as expected. It seems like the migration guide is missing a step or two?

1reaction
Frikkicommented, Jan 11, 2021

Any news? This seems vital to the purpose of Nx!

Read more comments on GitHub >

github_iconTop Results From Across the Web

nrwl-nx/community - Gitter
Hello Everyone. I am trying to test a fetch endpoint but am running into cors issue. is there a way to create a...
Read more >
create-nx-workspace - CLI command
Create a new Nx workspace. ... appName. Type: string. The name of the application when a preset with pregenerated app is selected ...
Read more >
@nrwl/web - npm
The Nx Plugin for Web Components contains generators for managing Web Component applications and libraries within an Nx workspace.
Read more >
Building Full-Stack Applications Using Angular CLI and Nx
Nx is just an extension for the Angular CLI, so create-nx-workspace simple runs ng new myorg --collection=@nrwl/schematics and handles common pitfalls of ...
Read more >
Angular workspace configuration
Configures defaults for creating a Universal application with server-side rendering, using the ng run <project>:server command. architect/app-shell, Configures ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found