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

HookWebpackError: filenameForRelatedName.indexOf is not a function #240

Closed
gqgs opened this issue Jan 9, 2021 · 5 comments · Fixed by #241
Closed

HookWebpackError: filenameForRelatedName.indexOf is not a function #240

gqgs opened this issue Jan 9, 2021 · 5 comments · Fixed by #241

Comments

@gqgs
Copy link

gqgs commented Jan 9, 2021

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

@alexander-akait
Copy link
Member

Yep, bug

@alexander-akait
Copy link
Member

alexander-akait commented Jan 9, 2021

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
Copy link
Author

gqgs commented Jan 9, 2021

@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.

@alexander-akait
Copy link
Member

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

@gqgs
Copy link
Author

gqgs commented Jan 11, 2021

@alexander-akait Thank you.

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