awesome-webextension / webpack-target-webextension

WebExtension Target for Webpack 5. Supports code-splitting and HMR.
MIT License
44 stars 5 forks source link

__webpack_require__.e is not a function in MV3 #33

Closed Jack-Works closed 2 years ago

Jack-Works commented 2 years ago

Temporary workaround: Adding a dynamic import in your source code

I should add .e to the dependency but I don't have the resources to do that. PR welcome.

h3xstream commented 2 years ago

I had the same issue. https://stackoverflow.com/questions/73368771/uncaught-typeerror-webpack-require-e-is-not-a-function

Jack-Works commented 2 years ago

does the workaround work for you?

JamiesWhiteShirt commented 2 years ago

Disabling the eagerChunkLoading option works for me, though I'd like to resolve this properly. I'm looking into contributing a fix, though I'm not fully familiar with Webpack plugin development.

The way I understand the issue is that when eager chunk loading and Manifest V3 is enabled, a runtime module is added to load chunks eagerly which requires RuntimeGlobals.ensureChunk, but this runtime requirement is not declared so that the runtime module that installs RuntimeGlobals.ensureChunk is not necessarily added. Adding a dynamic import has the side effect of adding a runtime requirement on RuntimeGlobals.ensureChunk, which is why it works as a workaround.

Would the solution be to, in addition to adding EagerlyLoadChunksRuntimeModule to the background entry chunk, tapping Compilation.hooks.additionalTreeRuntimeRequirements and adding RuntimeGlobals.ensureChunk to runtimeRequirements on the background entry chunk, or is there a fancier method to add a runtime requirement?

Jack-Works commented 2 years ago

hi @crimx can u release a new version?

crimx commented 2 years ago

Sure. webpack-target-webextension@1.0.4 publish. @Jack-Works feel free to publish new versions as you already had write access to the package. 🚀