Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dusandz opened this issue Oct 31, 2023 · 0 comments

Comments

@dusandz
Copy link

dusandz commented Oct 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant