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

Cannot find module '@nrwl/webpack/package.json' #14531

Closed
rpspall opened this issue Jan 21, 2023 · 29 comments · Fixed by #14546 or #15062
Closed

Cannot find module '@nrwl/webpack/package.json' #14531

rpspall opened this issue Jan 21, 2023 · 29 comments · Fixed by #14546 or #15062
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@rpspall
Copy link

rpspall commented Jan 21, 2023

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

@rpspall
Copy link
Author

rpspall commented Jan 22, 2023

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.

@Crocsx
Copy link

Crocsx commented Jan 23, 2023

Same here, I use 15.4.X works fine, updating to 15.5.X fail any Nx command with
Unable to resolve @nrwl/webpack:dev-server.

@jodan13
Copy link

jodan13 commented Jan 23, 2023

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'

@bigcakes
Copy link
Contributor

I hit this error as well, and for me the issue was that they removed the dependency from nrwl/web on nrwl/webpack, so I just explicitly specified the dependency and this stopped failing at least.

@jaysoo
Copy link
Member

jaysoo commented Jan 23, 2023

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.

@tamas-kasa
Copy link

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?

@mandarini
Copy link
Member

Can you try installing the @nrwl/webpack package? Like, yarn add -D @nrwl/webpack or npm install --save-dev @nrwl/webpack?

@tamas-kasa
Copy link

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 :(

@vcardins
Copy link

vcardins commented Feb 15, 2023

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.

@tamas-kasa
Copy link

@vcardins totally agree. It's very disappointing. Is there anything I can do for you guys to help you tackle this down?

@mandarini mandarini reopened this Feb 16, 2023
@mandarini
Copy link
Member

Hi all! I am sorry you are disappointed in Nx. I will try to track down the source of this and provide a fix.

@tamas-kasa can you give me steps on how to reproduce? The way I can reproduce this is to follow the tutorial, right?
Or should I follow the tutorial with an older version and then migrate to latest and see the issue?

@mandarini
Copy link
Member

mandarini commented Feb 16, 2023

Linking this issue here: #14807

@tamas-kasa @vcardins

When I follow the tutorial to the letter, I get the error reported in the above issue. I don't get the webpack error.

The error reported in the above issue is fixable if you create the file libs/products/.babelrc with the contents:

{ "presets": ["@nrwl/react/babel"] }

Can you tell me how I can reproduce your issue? Which version of Nx did you start with?

@tamas-kasa
Copy link

Yes, so basically I created the monorepo with Nx version 15.2.1 a long time ago. And I tried to migrate to 15.7.0. (I also tried to migrate to the next minor version step by step. but for now, let's focus on migrating straight to the latest version)

nx --version
# 15.2.1
nx migrate latest
npm install
nx --version
# 15.7.0
nx migrate --run-migrations
rm migrations.json
nx run my-app:serve:development

:(

Cannot find module '@nrwl/webpack'

@mandarini
Copy link
Member

Ok, I will try these steps in a minute, thanks!

@mandarini
Copy link
Member

Ok @tamas-kasa thank you for the detailed reproduction steps. I finally managed to reproduce your issue. For me, just installing @nrwl/webpack makes it work. I did not need to install all the other things mentioned in your comment above. Here is my repro repo.

So, I will add now a migrator, that if a workspace is using @nrwl/webpack and @nrwl/webpack is not installed, it should install it.

Does this sound like a good solution?

@mandarini
Copy link
Member

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!

@tamas-kasa
Copy link

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

@mandarini
Copy link
Member

Hmmm I am not sure to be honest. :( Sorry!!

@tamas-kasa
Copy link

Anyways! Thank you so much for your help. 🙏

@vcardins
Copy link

It didn't work for me, the commands I ran were:
nx migrate latest && npx nx g @nrwl/webpack:init --uiFramework=react && yarn and I got

Unable to resolve @nrwl/webpack:init.

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

@mandarini
Copy link
Member

Hey @vcardins ! When you tried that command, the commit fixing this issue was not in a release yet. Please can you manually install @nrwl/webpack for now, to get unblocked?

@tamas-kasa
Copy link

@mandarini I tried to migrate to 15.7.2 but it still doesn't work.

Steps to reproduce:

I'm on 15.2.1 and run:

npx nx migrate 15.7.2

then I run npm i and npx nx migrate --run migrations

and then I'm still getting:

Cannot find module '@nrwl/webpack'

@mandarini
Copy link
Member

mandarini commented Feb 28, 2023

@tamas-kasa it's not in a release yet! Here is the commit. It's on 15.8.0-beta! :) To get unblocked, you may manually install the missing dependencies for now!

@tamas-kasa
Copy link

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

@72gm
Copy link

72gm commented Feb 28, 2023

I was having the same issues after trying to migrate to 15.7.2... so upgraded to 15.8.0-beta.8 ... and it literally broke everything

WARNING in ../../node_modules/sax/lib/sax.js 163:13-37
Module not found: Error: Can't resolve 'stream' in 'C:\Dev\NX\monorepo\node_modules\sax\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }

ERROR in ../../node_modules/@azure/core-http/dist/index.js 12:9-22
Module not found: Error: Can't resolve 'os' in 'C:\Dev\NX\monorepo\node_modules@azure\core-http\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }

ERROR in ../../node_modules/@azure/core-http/dist/index.js 13:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Dev\NX\monorepo\node_modules@azure\core-http\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }

ERROR in ../../node_modules/@azure/core-http/dist/index.js 14:12-28
Module not found: Error: Can't resolve 'https' in 'C:\Dev\NX\monorepo\node_modules@azure\core-http\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }

ERROR in ../../node_modules/@azure/core-http/dist/index.js 17:13-30
Module not found: Error: Can't resolve 'stream' in 'C:\Dev\NX\monorepo\node_modules@azure\core-http\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }

ERROR in ../../node_modules/@azure/core-util/dist/index.js 6:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Dev\NX\monorepo\node_modules@azure\core-util\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }

ERROR in ../../node_modules/@azure/logger/dist/index.js 8:9-22
Module not found: Error: Can't resolve 'os' in 'C:\Dev\NX\monorepo\node_modules@azure\logger\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }

ERROR in ../../node_modules/@azure/storage-blob/dist/index.js 11:13-30
Module not found: Error: Can't resolve 'crypto' in 'C:\Dev\NX\monorepo\node_modules@azure\storage-blob\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }

ERROR in ../../node_modules/@azure/storage-blob/dist/index.js 12:13-30
Module not found: Error: Can't resolve 'stream' in 'C:\Dev\NX\monorepo\node_modules@azure\storage-blob\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }

ERROR in ../../node_modules/tunnel/lib/tunnel.js 3:10-24
Module not found: Error: Can't resolve 'net' in 'C:\Dev\NX\monorepo\node_modules\tunnel\lib'

ERROR in ../../node_modules/tunnel/lib/tunnel.js 4:10-24
Module not found: Error: Can't resolve 'tls' in 'C:\Dev\NX\monorepo\node_modules\tunnel\lib'

ERROR in ../../node_modules/tunnel/lib/tunnel.js 5:11-26
Module not found: Error: Can't resolve 'http' in 'C:\Dev\NX\monorepo\node_modules\tunnel\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }

ERROR in ../../node_modules/tunnel/lib/tunnel.js 6:12-28
Module not found: Error: Can't resolve 'https' in 'C:\Dev\NX\monorepo\node_modules\tunnel\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }

ERROR in ../../node_modules/xml2js/lib/parser.js 17:17-47
Module not found: Error: Can't resolve 'timers' in 'C:\Dev\NX\monorepo\node_modules\xml2js\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }'
- install 'timers-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "timers": false }

webpack compiled with 13 errors and 1 warning (dbe14ed8a0b43cb3)

@mandarini
Copy link
Member

@72gm I am sorry that happened to you! Can you please send me a reproduction repository so that I can help? Also, this looks like a different issue. Do you mind opening a new bug report? Thank you for reporting it!!

@marekopatril
Copy link

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 :)

@quyphan97
Copy link

image
I used v.15.8.7 but when I build the linux server I still get this error, is there any way to help me?

@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 Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet