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

__webpack_require__(null) when using manual splitChunks, concatenateModules #11856

Closed
Knagis opened this issue Oct 28, 2020 · 7 comments · Fixed by #11861
Closed

__webpack_require__(null) when using manual splitChunks, concatenateModules #11856

Knagis opened this issue Oct 28, 2020 · 7 comments · Fixed by #11861

Comments

@Knagis
Copy link
Contributor

Knagis commented Oct 28, 2020

Bug report

What is the current behavior?

This might be closely related to #11770.

// EXTERNAL MODULE: ./packages/path/SomeModule.ts
var SomeModule = __webpack_require__(null);

obviously moduleId null does not work... This module is one that is extracted into a common chunk as part of concatenated module with some ID like 784404 - an ID that is not referenced anywhere at all.

If the current behavior is a bug, please provide the steps to reproduce.

Reproduces in our huge monorepo, so far no luck in creating a small reproduction. Even in our repo, building just the parts affected do not reproduce it, only building everything (~40 entries) produces the error.

Some notes:

  • reproduces in production mode
  • building with devTool: false.
  • setting innerGraph: false does not affect the issue.
  • setting concatenateModules: false "fixes" the issue
  • setting usedExports: "global" also "fixes" the issue

What is the expected behavior?

Correctly generated chunks with no missing modules.

Btw, moduleId: null if it does happen, should perhaps throw during build since it will never work at runtime.

Other relevant information:
webpack version: 5.3.0
Node.js version: 12.13.1
Operating System: any
Additional tools:

@Knagis Knagis changed the title __webpack_require__(null) when using manual splitChunks, moduleConcatenation __webpack_require__(null) when using manual splitChunks, concatenateModules Oct 28, 2020
@Knagis
Copy link
Contributor Author

Knagis commented Oct 28, 2020

usedExports: "global" also prevents the issue

@sokra
Copy link
Member

sokra commented Oct 28, 2020

Hmm yes that really sounds related to that. To me it sounds like a bug in the module concatenation, especially the algorithm that selects which modules are concatenated. Probably related to the runtime filtering. I have one idea which I can try to figure out how to reproduce it (note to myself: entry A -> c -> d, entry B -> d, c and d force to chunk, c + d concatenated, maybe c -> d conditional).

@sokra
Copy link
Member

sokra commented Oct 28, 2020

Ok I found something. Looks really like your issue. I'm pretty sure #11861 fixes your issue, but it would be great if you could test it in your codebase.

"webpack": "webpack/webpack#bugfix/11856

@Knagis
Copy link
Contributor Author

Knagis commented Oct 28, 2020

Yes, just tested and this issue is fixed in the branch.

@YikaJ
Copy link

YikaJ commented Apr 8, 2021

webpack@5.31.0 still get this problem

image

concatenateModules: false can fix it。

@Knagis @sokra Could you reopen this issue?

@paradite
Copy link

paradite commented Apr 15, 2021

same issue here with webpack@5.31.2. We are doing a re-export of modules if that helps.


Update: it turns out from webpack/webpack.js.org#4837 the solution is to just remove new webpack.optimize.ModuleConcatenationPlugin(), which solved the error for me.

@zdila
Copy link

zdila commented Apr 20, 2021

I've just migrated our project from webpack 4 to webpack 5 and also experience this issue. Referenced null module is not instructed to be a chunk. It constains a single object that is default-exported:

export default {
   // some properties
}

Removing new webpack.optimize.ModuleConcatenationPlugin() fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants