nx: Cannot find module 'webpack' on fresh installation
I have a fresh installation of NX for React project; I got this message when try to serve the React project from VSCode NX toolkit.
> Executing task: nx serve fe-ui-compoents <
> nx run fe-ui-compoents:serve
Cannot find module 'webpack'
Require stack:
- /Users/nv/projects/x/y/node_modules/webpack-dev-server/lib/Server.js
- /Users/nv/projects/x/y/node_modules/@nrwl/web/src/executors/dev-server/dev-server.impl.js
- /Users/nv/projects/x/y/node_modules/@nrwl/tao/src/shared/workspace.js
- /Users/nv/projects/x/y/node_modules/@nrwl/tao/src/commands/run.js
- /Users/nv/projects/x/y/node_modules/@nrwl/tao/index.js
- /Users/nv/projects/x/y/node_modules/@nrwl/cli/lib/run-cli.js
———————————————————————————————————————————————
> NX ERROR Running target "fe-ui-compoents:serve" failed
Failed tasks:
- fe-ui-compoents:serve
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 30 (2 by maintainers)
Same problem here after a fresh installation, using angular project, solved with:
I faced the same problem with
npx create-nx-workspace-> preset: emptynpm i --save-dev @nrwl/angularnpx nx g @nrwl/angular:application-> name: appnpx nx run app:buildInstalled nx version is 13.3.1
Resulting in
Resolved the build and serve target issue by installing webpack manually:
Same thing here after upgrade.
Cannot find module ‘webpack’ Require stack:
I got this error because I had two dependencies (
webpack-dev-serverand@types/webpack) that required different versions ofwebpackas their own dependency. This causedwebpackto be installed in the subdirectories of those dependencies instead of directly at the root of thenode_modulesdirectory (i.e.node_modules/webpack). Once I removed@types/webpackfrom mydevDependencies, deleted mypackage-lock.jsonandnode_modules, and rannpm i,webpackwas installed tonode_modules/webpack, and the issue went away.@peterblazejewicz Yes I too got the same issue and had to install webpack manually using below command:
npm i --save-dev webpackIt resolved my issue