Skip to content

asset/inline Asset Module complains about generator property which isn't there #1237

Closed
@dusandz

Description

@dusandz

I'm having an issue with asset/inline and would appreciate some help.

This is the rule I'm trying to add:

 .addRule({
        test: /my-module[/\\]static-assets/,
        type: 'asset/inline',
    })

And that triggers a warning when I try to build the assets:

warn  in ./assets/js/my-module/static-assets/ sync ^\.\/.*$                                                                                                                                     

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 { dataUrl? }
   -> Generator options for asset/inline modules.

The error message makes sense (there are no filenames for inlined assets), but I'm not passing any filename parameters to the rule. Thinking that something might be happening under the hood, I tried modifying the config manually:

config = Encore.getWebpackConfig();
config.module.rules.push({
    test: /my-module[/\\]static-assets/,
    type: 'asset/inline',
})
module.exports = config

...but that didn't help. Just as a sanity check, I console-logged that part of the config:

  { test: /my-module[/\\]static-assets/, type: 'asset/inline' }

Looks good, but still complains about the filename.
Then I tried writing generator directive explicitly (thinking that Webpack or Encore might be adding its own, if omitted):

{
    test: /my-module[/\\]static-assets/,
    type: 'asset/inline',
    generator: {
        dataUrl: content => {
            return content.toString('base64');
        }
    }
}

...to no avail. Tried on an isolated piece of code (just Webpack), worked fine there.

I can work around this and load the static assets manually using fetch, but I'm really curious to learn what did I do wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions