Webpack 5 plugin: No code generation entry for module error

530 views Asked by At

While upgrading a plugin I'm maintaining to support both Webpack 4 and 5 I've ran into the following brick wall for which I can't find any information at all and no one on Gitter seems to be able to help either.

The plugin adds an asset (SVG spritemap) to compilation.assets which is working without problems. There's a feature in the plugin that allows users to keep the created chunk which is needed for interoperability with some other plugins. The minimal working code for Webpack 4 would be along the lines of (and always felt a bit hacky to me, but it worked ‍♂️):

// OutputOptions.chunk.name would equal 'spritemap' in this example
const chunk = compilation.addChunk(outputOptions.chunk.name);
const module = new RawModule('', `${outputOptions.chunk.name}-dummy-module`);

chunk.addModule(module);

Using that same approach with Webpack 5 throws the following error:

ERROR in spritemap.js
No code generation entry for spritemap-dummy-module (existing entries: <path-to>/svg-spritemap-webpack-plugin/examples/simple/src/index.js)

It also shows a deprecation warning for Chunk.addModule which I can fix by using compilation.chunkGraph.connectChunkAndModule(chunk, module); instead but this (obviously) doesn't get rid of the code generation entry error.

1

There are 1 answers

0
Cas Cornelissen On

I ended up posting the same question as a GitHub issue since I wasn't getting any replies on Gitter and Stack Overflow. Tobias Koppers pushed me in the right direction with a suggestion to make sure the module was added to compilation.modules. So in the end this specific issue was solved by the following code:

compilation.modules.add(module);