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

Next 10.0.6 , Build Error: Cannot find module 'webpack' #151

Closed
meotimdihia opened this issue Jan 30, 2021 · 31 comments
Closed

Next 10.0.6 , Build Error: Cannot find module 'webpack' #151

meotimdihia opened this issue Jan 30, 2021 · 31 comments
Labels
bug Something isn't working

Comments

@meotimdihia
Copy link

meotimdihia commented Jan 30, 2021

Summary

Next 10.0.6 , Build Error: Cannot find module 'webpack'

  • C:\sources\a\node_modules\workbox-webpack-plugin\build\generate-sw.js
  • C:\sources\a\node_modules\workbox-webpack-plugin\build\index.js
  • C:\sources\a\node_modules\next-pwa\index.js
  • C:\sources\a\next.config.js
  • C:\sources\a\node_modules\next\dist\next-server\server\config.js
  • C:\sources\a\node_modules\next\dist\build\index.js
  • C:\sources\a\node_modules\next\dist\cli\next-build.js
  • C:\sources\a\node_modules\next\dist\bin\next

How To Reproduce

yarn build with.:

  • next: 10.0.6, 10.0.7
  • next-pwa ^5.0.3
@meotimdihia meotimdihia added the bug Something isn't working label Jan 30, 2021
@otekdo
Copy link

otekdo commented Jan 30, 2021

I also have this problem too!
The same exact response as you mentioned!
I had to downgrade to Next 10.0.5!

@champseo2017
Copy link

I also have this problem too!

@srijanshetty
Copy link

Same issues with my builds in GitHub Actions. This does not happen with local cached builds, but a new build always fails.

@ReeceM
Copy link

ReeceM commented Jan 31, 2021

So I just updated, and I have the same issue.

But when trying to clear node_modules, package-lock.json and reinstalling, this is the following:

npm WARN babel-loader@8.2.2 requires a peer of webpack@>=2 but none is installed. You must install peer dependencies yourself.
npm WARN clean-webpack-plugin@3.0.0 requires a peer of webpack@* but none is installed. You must install peer dependencies yourself.
npm WARN next-pwa@5.0.4 requires a peer of webpack@>=4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN workbox-webpack-plugin@6.1.0 requires a peer of webpack@^4.4.0 || ^5.9.0 but none is installed. You must install peer dependencies yourself.

So, am I reading this correctly that nothing is installing web pack by default and that it's up to the end user to manage this bit?

Aside

I recall having this moving to version 10.0.5 last time, but cannot recall what actually fixed it.

@theoludwig
Copy link

This issue also has been reported to vercel/next.js repo : vercel/next.js#21679
@otekdo Indeed downgrading to next@10.0.5 solves the issue but it would be better to fix the issue with latest version of next.

Currently next-pwa depends of webpack in peerDependencies :

next-pwa/package.json

Lines 27 to 30 in 9dc7c26

"peerDependencies": {
"next": ">=7.0.0",
"webpack": ">=4.0.0"
}

Maybe this commit is related : vercel/next.js@099cd30#diff-9c1a3867443c54525b4f24ef171f231a6e8bb065ffc8b7b62c4843d5ff62dd42L106-L108

Could be cool, if we find a solution for latest version of next.

@otekdo
Copy link

otekdo commented Feb 1, 2021

@divlo Thanks for the tip!
but right now, i'll keep it to 10.0.5, i'll wait for the solution
i do not really need 10.0.6, i updated because there could be some perfomance optimization or other stuff!

@shadowwalker
Copy link
Owner

Try to add webpack with following command should help fix this issue:

yarn add webpack@webpack-4

@theoludwig
Copy link

@shadowwalker It solves the issue, but in my opinion next or next-pwa should handle this for us (users), as it was the case with next@10.0.5. We should not handle a webpack version in our devDependencies.
I don't know from where the error is coming from, and I don't know the codebase of this library, but I guess it's solvable without adding extra-dependencies for the users.

@carloscuesta
Copy link

Totally agree with @divlo that's something that next or next-pwa should handle.

If I'm not mistaken, I think that what's happening here is that next-pwa assumes that webpack is a dependency that is satisfied by next that's why it's working at 10.0.5

@ReeceM
Copy link

ReeceM commented Feb 2, 2021

I do believe that next-pwa uses workbox, and that is requiring webpack directly in the code that is throwing the error.

I don't think this repo directly depends on it, but rather only has it as a development dependency, and is relying on the fact that the end user is using webpack and so is the workbox package.

NextJS appears to have made the dependency of webpack handled internally and that removed the natrual availability of the webpack package.

I see that there are requirements for peer dependencies in this package for webpack, and I think the workbox one when installing.

@shadowwalker Is there the intention that the end user needs to have workbox installed? Or was it being statisfied as a requirement when NextJS was supplying Webpack and that the user initially didn't notice? (myself included)

@isggwp
Copy link

isggwp commented Feb 2, 2021

I have no idea what's going on with webpack. I just roll back from next@10.0.6 to next@10.0.5 until this issue solved.

@shadowwalker
Copy link
Owner

next.js should includes webpack and next-pwa will use that. This is how it works before, I'm not sure what's going on with latest changes and webpack 5 updates. Still investigating.

@ReeceM
Copy link

ReeceM commented Feb 2, 2021

next.js should includes webpack and next-pwa will use that. This is how it works before, I'm not sure what's going on with latest changes and webpack 5 updates. Still investigating.

@shadowwalker what I noticed, between 10.0.6 canary-0 (this canary build works) and canary-1 webpack was removed as a dependency of nextjs and changed to an internally built and managed instance, so all referenced webpack instances that they used were changed to one under a dist directory.

The thing that I noticed is that with next-pwa the error comes mainly from the workbox package as it requires an instance of web pack but still declares it under devDependencies So it isn’t really ever added in a end users node_modules folder.

I am not sure if there is a way to reference the nextjs version and then declare it for workbox to find. But that would cause a similar issue as now. So that would be bad idea.

@timneutkens
Copy link

Posted an explanation here: vercel/next.js#21679 (comment)

@BjoernRave
Copy link

With the help of the explanation of @timneutkens I got it to work by adding require('webpack') to next.config.js and installing webpack@4 as dependency

@timmalstead-cfa
Copy link

I can confirm that the solution from @timneutkens and @BjoernRave works.

In my case, it was necessary to keep next at 10.0.5 and next-pwa at 5.0.3 and then install webpack@4.4.0 under devDependencies.

Thanks so much!

@jatinhemnani01
Copy link

so should I downgrade my next version to 10.0.5 ?

@shadowwalker
Copy link
Owner

@timneutkens I read your comments here vercel/next.js#21679 (comment), but still couldn't figure out what I should change in next-pwa to minimize the impact for the users of next.js 10.0.6 and next-pwa plugin. Could you provide some more advice on this issue? Thanks.

@digitaltim-de
Copy link

Same problem..

@ReeceM
Copy link

ReeceM commented Feb 7, 2021

As I had the issue coming from this package and next.js combined, the following was a solution: vercel/next.js#21679 (comment)

It seems that it will have to do until 10.0.7 of next.js comes out

@tarun1992
Copy link

I am also facing the same issue. Is there any solution as Webpack solution didn't work for me.

@ReeceM
Copy link

ReeceM commented Feb 12, 2021

I am also facing the same issue. Is there any solution as Webpack solution didn't work for me.

@tarun1992 maybe try Tim Neutkens suggestion as there is a patch in the canary version of nextjs, vercel/next.js#21679 (comment)

@theoludwig
Copy link

I tried vercel/next.js#21679 (comment)
So I use next@10.0.7-canary.8 and next-pwa@5.0.5 with npm@6 because with npm@7 the installation fails because the peer dependency are unmet.

But it isn't working, I still got the error :

Error: Cannot find module 'webpack'
Require stack:
- /home/divlo/Documents/Thream/website/node_modules/workbox-webpack-plugin/build/generate-sw.js
- /home/divlo/Documents/Thream/website/node_modules/workbox-webpack-plugin/build/index.js
- /home/divlo/Documents/Thream/website/node_modules/next-pwa/index.js

...
etc.

@rookledookle
Copy link

Facing the same issue with next 10.0.7

@leerle56
Copy link

leerle56 commented Feb 28, 2021

Facing the same issue with next 10.0.7

I have fixed it by install webpack@4 in 10.0.7...

@Gilson401
Copy link

Facing the same issue with next 10.0.1 (!)

@dcateflexera
Copy link

I am still getting this issue with next v 10.0.7.

I added a next.config.js file to the root of the repo and the following code produces the error:

const withLess = require('@zeit/next-less')
  module.exports = withLess({
   /* config options here */
})

@carloscuesta
Copy link

carloscuesta commented Mar 6, 2021

The issue is fixed at Next 10.0.8, upgraded today from 10.0.5 and had no problems!

Fixed at: vercel/next.js#22583

@meotimdihia
Copy link
Author

Yes, I think we can close this issue now.

@shadowwalker
Copy link
Owner

Great, glad the issue is fixed with next.js 10.0.8. Please create a new issue if there are other concerns.

@Hocdoc
Copy link

Hocdoc commented Mar 16, 2021

I have to remove node_modules. After that, this error dissapeared:

rm -rf node_modules/
npm install
npm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests