intoli/antd-scss-theme-plugin

TypeError: compilation.fileDependencies.includes is not a function

RobinRadic opened this issue · 5 comments

Got this error

node_modules/antd-scss-theme-plugin/build/dist/lib/index.js:21
      if (compilation.fileDependencies && !compilation.fileDependencies.includes(theme)) {
                                                                        ^
TypeError: compilation.fileDependencies.includes is not a function

Ran it with debugger on, it showed me compilation.fileDependencies is not an array but a Set.

My workaround:

export class AntdScssTheme extends AntdScssThemePlugin {

    apply(compiler) {
        const afterEmit = (compilation, callback) => {
            // Watch the theme file for changes.
            const theme = AntdScssThemePlugin.SCSS_THEME_PATH;
            if ( compilation.fileDependencies && ! compilation.fileDependencies.has(theme) ) { // modified
                compilation.fileDependencies.add(theme); // modified
            }
            callback();
        };

        // Register the callback for...
        if ( compiler.hooks ) {
            // ... webpack 4, or...
            const plugin = { name: 'AntdScssThemePlugin' };
            compiler.hooks.afterEmit.tapAsync(plugin, afterEmit);
        } else {
            // ... webpack 3.
            compiler.plugin('after-emit', afterEmit);
        }
    }
}
prncc commented

I think that fileDependencies was changed to a set from an array in Webpack 4. Which version of Webpack are you using?

Either way, thanks for reporting; I'll get it fixed first thing.

webpack@4.10.2

I'm having the same issue with webpack@4.8.3
@RobinRadic fix solves the issue. Thanks

I'm also having this issue, @RobinRadic fix is also working here, do you have some estimation about when you will apply this code in your plugin?

prncc commented

Thanks @vieira! This fix is live as of v1.0.4. @samuel-alpoim @sinisavukovic @RobinRadic