[英]Webpack 5 plugin: No code generation entry for module error
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.在升级插件以支持 Webpack 4 和 5 时,我遇到了以下砖墙,我根本找不到任何信息,而且Gitter上的任何人似乎也无法提供帮助。
The plugin adds an asset (SVG spritemap) to compilation.assets
which is working without problems.该插件增加了一个资产(SVG spritemap)至compilation.assets
这是工作没有问题。 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 🤷🏼♂️): Webpack 4 的最小工作代码大致如下(对我来说总是觉得有点 hacky,但它确实有效🤷🏼♂️):
// 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:对 Webpack 5 使用相同的方法会引发以下错误:
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);
它还显示了Chunk.addModule
的弃用警告,我可以使用Chunk.addModule
compilation.chunkGraph.connectChunkAndModule(chunk, module);
修复它compilation.chunkGraph.connectChunkAndModule(chunk, module);
instead but this (obviously) doesn't get rid of the code generation entry error.相反,但这(显然)并没有摆脱代码生成条目错误。
I ended up posting the same question as a GitHub issue since I wasn't getting any replies on Gitter and Stack Overflow.我最终发布了与GitHub 问题相同的问题,因为我没有收到关于 Gitter 和 Stack Overflow 的任何回复。 Tobias Koppers pushed me in the right direction with a suggestion to make sure the module was added to compilation.modules
. Tobias Koppers 将我推向了正确的方向,并提出了一个建议,以确保将模块添加到compilation.modules
。 So in the end this specific issue was solved by the following code:所以最终这个特定问题是通过以下代码解决的:
compilation.modules.add(module);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.