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

[Regression] - ModuleNotFoundError: when running production build (and eating underlying error) #22200

Closed
jasonwilliams opened this issue Feb 15, 2021 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@jasonwilliams
Copy link

jasonwilliams commented Feb 15, 2021

What version of Next.js are you using?

10.0.7 (Issue looks like it was introduced in 10.0.6)

What version of Node.js are you using?

15

What browser are you using?

Chrome

What operating system are you using?

MacOS

How are you deploying your application?

next start

Describe the Bug

Updating to Webpack 5.21.2 alongside Next 10.0.6 causes ModuleNotFound errors when using ignorePlugin.
We don't get the error when rolling back to 10.0.5

When building in development next we have no issues with our pages.
however when running next build we get an error:

info  - Creating an optimized production build  
Failed to compile.

ModuleNotFoundError: Module not found: TypeError: Cannot read property 'request' of null


> Build error occurred
Error: > Build failed because of webpack errors
    at home/project/node_modules/next/dist/build/index.js:15:929
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async home/project/node_modules/next/dist/build/tracer.js:1:1596

Issue 1: underlying error was eaten

The above wasn't very helpful as it doesn't tell me what caused it or what was trying to be loaded.
I managed to search for the ModuleNotFoundError class and log out the error before it.
It was in /node_modules/next/dist/compiled/webpack/bundle4.js

Now i can see:

null
TypeError: Cannot read property 'request' of null
    at IgnorePlugin.checkIgnore (/home/project/node_modules/webpack/lib/IgnorePlugin.js:50:49)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (/home/project/node_modules/next/dist/compiled/webpack/bundle4.js:47182:10), <anonymous>:21:16)
    at NormalModuleFactory.create (/home/project/node_modules/next/dist/compiled/webpack/bundle4.js:67799:28)
    at /home/project/node_modules/next/dist/compiled/webpack/bundle4.js:54821:14
    at Semaphore._continue (/home/project/node_modules/next/dist/compiled/webpack/bundle4.js:93245:5)
    at processTicksAndRejections (node:internal/process/task_queues:75:11)

Issue 2: null being passed to webpack/ignorePlugin

It looks like in production next passes null to ignorePlugin, specifically here.
Im not sure why this only happens on production builds but it seems to have only happened since updating to webpack 5

Expected Behavior

production builds should work

To Reproduce

@jasonwilliams jasonwilliams added the bug Issue was opened via the bug report template. label Feb 15, 2021
@jasonwilliams jasonwilliams changed the title ModuleNotFoundError: when running production build (and eating underlying error) [Regression] - ModuleNotFoundError: when running production build (and eating underlying error) Feb 16, 2021
@gfortaine
Copy link
Contributor

It looks like that this error is a regression coming from webpack : webpack/webpack#8538

@jasonwilliams
Copy link
Author

@gfortaine im sure it’s related to this #21679 (comment)

@gfortaine
Copy link
Contributor

@jasonwilliams Many thanks 👍 We do confirm that by setting the following in next.config.js:

// next.config.js
module.exports = {
  future: { webpack5: true }
}

the bug disappears with next 10.0.6 in your test repo : https://github.com/gfortaine/nextjs9-typescript-server-vscode-example/tree/moduleNotFound

@jasonwilliams
Copy link
Author

jasonwilliams commented Feb 21, 2021

@timneutkens I understand webpack 5 support is “beta” but was there a reason to make such a breaking change on a patch release? The documentation hasn’t been updated to mention the change in how you opt in (it still only mentions resolutions) so this would have broken for anyone using webpack 5 with plugins. I only found that fix by chance on another issue.

I’m not the first person to raise this as a problem

(this issue comes top when searching Webpack 5 and next, it would be worth putting something here for those who fall into this problem)
#13341

@gfortaine thanks for testing

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants