Bug report: Webpack build fails with Invalid generator object for overlapping asset/inline rules
Describe the bug
The webpack build fails with a ValidationError caused by two overlapping module rules for \.(png|jpg|gif)$ files. When a file matches both rules simultaneously, webpack merges their configs — resulting in an asset/inline module that inherits generator: { filename: ... } from the asset/resource rule. The filename property is not valid for asset/inline modules, causing the build to fail.
To Reproduce Steps to reproduce the behaviour or a link to the recipe / input used to cause the bug:
- Clone the CyberChef repository
- Run
npm install - Run the webpack build (e.g.
npm run build) - Observe the following error:
Module not found: ValidationError: Invalid generator object. Asset Modules Plugin has been initialized using a generator object that does not match the API schema.
- generator has an unknown property 'filename'. These properties are valid:
object { binary?, dataUrl? }
-> Generator options for asset/inline modules.
Expected behaviour
The build should complete successfully. First-party images (not in node_modules) should be emitted as resource files, and third-party images (in node_modules) should be inlined — with no rule overlap.
Screenshots N/A — build-time error reproducible from the terminal.
Root cause
In webpack.config.js, two rules both match the same files:
{ // First party images are saved as files to be cached
test: /\.(png|jpg|gif)$/,
exclude: /(node_modules|bmfonts)/,
type: "asset/resource",
generator: { filename: "images/[name][ext]" }
},
{ // Third party images are inlined
test: /\.(png|jpg|gif)$/,
exclude: /web\/static/, // <-- too broad; does not restrict to node_modules
type: "asset/inline",
},
Any image not under node_modules, bmfonts, or web/static (e.g. a first-party image in web/images/) matches both rules. Webpack merges all matching rules, so the final module ends up with type: "asset/inline" (last rule wins) but retains generator: { filename: ... } from the first rule — an invalid combination.
Proposed fix
Change the second rule's exclude to an include so it only matches node_modules images, making the two rules mutually exclusive:
{ // Third party images are inlined
test: /\.(png|jpg|gif)$/,
include: /node_modules/,
type: "asset/inline",
},
Desktop (if relevant, please complete the following information):
- OS: Windows 11
- Browser: N/A (build-time issue)
- CyberChef version: current
masterbranch
Additional context
This issue exists in the current master branch of the upstream repository. The rule comments correctly describe the intent ("First party" vs "Third party"), but the exclude on the second rule does not correctly implement it.
I'm not seeing this locally (or in the recent CI build of master https://github.com/gchq/CyberChef/actions/runs/27340944734/job/80777289755)
Do you have a modified version of the tree, as so far as I can tell in the master on github the only first party images are in web/static/images or web/static/fonts/bmfonts (both of which are covered adequately by the current regexes).
That said I'll look into this further - at first sight your proposed fix looks reasonable, albeit the problem is not being triggered on the github master branch in my, or the CI, setup.
Windows 11; node v24.13.11.
Why it works on Linux
- Webpack matches rules against the absolute path of the files being processed.
- On Linux, the path to a first-party image looks like /home/user/project/web/static/logo.png.
- The regex /web/static/ successfully matches the web/static substring because of the forward slash.
- This correctly excludes first-party images from the second rule (asset/inline), meaning only the first rule (asset/resource) matches.
Why it fails on Windows
- On Windows, the absolute path to the same image looks like C:\project\web\static\logo.png.
- The regex /web/static/ looks specifically for a forward slash (web/static) and fails to match web\static.
- Because the exclusion fails, both rules match the file simultaneously: The first rule matches (since it's not excluded). The second rule matches (since the Windows path didn't trigger the /web/static/ exclusion).
- When Webpack encounters a module that matches multiple conflicting asset types (asset/resource vs. asset/inline), it throws a compilation/build error.