webpack-contrib/compression-webpack-plugin

HookWebpackError: filenameForRelatedName.indexOf is not a function

gqgs opened this issue · 5 comments

gqgs commented
  • compression-webpack-plugin Version: 7.1.1

Expected Behavior

The plugin to compress data as expected.

Actual Behavior

webpack crashes wtih a HookWebpackError after the plugin tries to access the indexOf of a function.

HookWebpackError: filenameForRelatedName.indexOf is not a function

Code

// webpack.config.js

const zopfli = require("@gfx/zopfli");

module.exports = {
  plugins: [
    new CompressionPlugin({
        filename(pathData) {
            // other things here...
            return "[path][name].gz";
        },
        algorithm(input, compressionOptions, callback) {
            return zopfli.gzip(input, compressionOptions, callback);
        },
    }),
  ],
};

How Do We Reproduce?

Apparently it happens if algorithm and filename properties are both defined as functions.
I could be missing something but it seems the case where filename is a function is being ignored in the section bellow.

if (typeof this.options.algorithm === "function") {
let filenameForRelatedName = this.options.filename;
const index = filenameForRelatedName.indexOf("?");

Yep, bug

Just interesting - why do you use it as function? zopfli supported by Node.js, using [path][name].gz doesn't have sense because it is static

gqgs commented

@alexander-akait I'm using a different algorithm and filename functions. I just used that from the docs since it'd be easier to reproduce/understand.

Yep, I will fix it tomorrow, thanks for the issue

gqgs commented

@alexander-akait Thank you.