nx: Cannot find module '@nrwl/webpack/package.json'

Current Behavior

Followed the nx dev tutorial TO THE LETTER 😃

https://nx.dev/react-tutorial

When I get to the “npx nx build admin” or “npx nx serve admin” steps I get an error:

Unable to resolve @nrwl/webpack:webpack for build

Unable to resolve @nrwl/webpack:dev-server for serve

I can fix the issue by adding “@nrwl/webpack”: “^15.5.2” to devDependencies in package.json (and running npm install)

I assume this is a correct fix? Meanwhile, is the tutorial broken?

Expected tutorial to work without additional steps, unsure if this is a documentation issue, or a bug?

Expected Behavior

Expected demo / tutorial to work without adding additional dependecies

Github Repo

No response

Steps to Reproduce

Followed the nx dev tutorial TO THE LETTER 😃

https://nx.dev/react-tutorial

Nx Report

Unable to resolve @nrwl/webpack:dev-server

Or

Unable to resolve @nrwl/webpack:webpack

Failure Logs

No response

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 29 (12 by maintainers)

Most upvoted comments

For anyone else running into this, you can manually install @nrwl/webpack and then you can run:

npx nx g @nrwl/webpack:init --uiFramework=react

in order to get all the other potential missing dependencies!

I’m a big fan and long time user of NX, but this issue has been around for a long time. I tried to migrate to 15.7.1 today and the same error (since 15.0.0). I think it should be really considered before releasing any next version.

Yes I tried (however I was promised it’s not needed anymore)

But then I get the following error:

Cannot find module 'react-refresh/babel'

Once I install react-refresh, I get the following error:

Cannot find module '@pmmmwh/react-refresh-webpack-plugin'

Once I install the aforementioned module, I get the following:

Cannot find module '@svgr/webpack'

Once I install that one too, everything is alright

Please don’t tell me this is the expected process 😦

Seems like 15.4.5 was last version OK, then I had. Went from 15.4.5 to 15.8.5 and getting:


Cannot find module '@nrwl/webpack/package.json'
  Require stack:
  - /Users/marek/Projects/online/node_modules/.pnpm/nx@15.8.5/node_modules/nx/src/utils/package-json.js
  - /Users/marek/Projects/online/node_modules/.pnpm/nx@15.8.5/node_modules/nx/src/utils/package-manager.js
  - /Users/marek/Projects/online/node_modules/.pnpm/nx@15.8.5/node_modules/nx/bin/init-local.js
  - /Users/marek/Projects/online/node_modules/.pnpm/nx@15.8.5/node_modules/nx/bin/nx.js
  Pass --verbose to see the stacktrace.

Solved with

rm -rf node_modules dist
pnpm i
pnpm add -D @nrwl/webpack
pnpm exec nx g @nrwl/webpack:init

PS: Cannot say if rm -rf part was important but its running 😃

Ah I see. I thought it was released with 15.7.2, sorry.

Anyways! Thank you so much for your help. 🙏

@mandarini hmm, yes sounds good. interesting you didn’t need to install the other packages. I used npm@8. Could it cause any troubles?

Hi,

I’m still getting the error @nrwl/webpack not found however I use nx 15.7.0 to migrate

how can I get rid if this error message when I run serve:development?

There is a bug where create-nx-workspace does not install @nrwl/webpack. This will be patched in the next release. For now the workaround is to install @nrwl/webpack manually.

Yes, I have the same problem, I follow the instructions for version “nx”: “15.5.3” gives an error message:

nx run host:serve:development --open NX Cannot find module ‘@nrwl/webpack/src/executors/dev-server/dev-server.impl’

This is a bug in 15.5.2…

When I follow the tutorial with 15.4.5 I don’t get this error and no need to manually adjust dependencies.