Skip to content

HookWebpackError: filenameForRelatedName.indexOf is not a function #240

@gqgs

Description

@gqgs
  • 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("?");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions