简体   繁体   English

Webpack 5 插件:没有模块错误的代码生成条目

[英]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.

相关问题 Webpack插件中的流水线代码生成 - Pipelined code generation in a webpack plugin 找不到输入模块:错误:无法解析&#39;html-webpack-plugin / lib / loader.js&#39; - Entry module not found: Error: Can't resolve 'html-webpack-plugin/lib/loader.j s' gulp&webpack:找不到Entry模块中的ERROR - gulp & webpack: ERROR in Entry module not found 未找到Entry Module中的错误 - 在Webpack配置文件中 - Error in Entry Module not found - in Webpack Config file 找不到webpack入口模块 - webpack entry module not found 错误:找不到模块 &#39;html-webpack-plugin&#39; - Webpack (React) - Error: Cannot find module 'html-webpack-plugin' - Webpack (React) Webpack 4:找不到入口模块中的错误:错误:无法解析&#39;./src&#39; - Webpack 4 : ERROR in Entry module not found: Error: Can't resolve './src' 更改 WebPack Chunk 的 chunk entry-module\deferred-modules | Angular 构建器 WebPack 插件 - Change the chunk entry-module\deferred-modules of WebPack Chunk | Angular Builders WebPack Plugin 重构后 Webpack 停止工作:未找到入口模块中的错误 - Webpack stopped working after refactoring: ERROR in Entry module not found 配置 webpack/typescript:入口模块中的错误 - 无法解析“./src” - Configuration webpack/typescript: ERROR in Entry module - Can't resolve './src'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM