Skip to content

[v6.0.0] TypeError: this.getOptions is not a function #631

@korbav

Description

@korbav

🐛 Bug Report

Last release v6.0.0 provoked the following issue : TypeError: this.getOptions is not a function

Which is referring to the following call:

function svgrLoader(
this: webpack.LoaderContext<LoaderOptions>,
contents: string,
): void {
this.cacheable && this.cacheable()
const callback = this.async()
const options = this.getOptions()
const previousExport = (() => {
if (contents.startsWith('export ')) return contents
const exportMatches = contents.match(/^module.exports\s*=\s*(.*)/)
return exportMatches ? `export default ${exportMatches[1]}` : null
})()

To Reproduce

Steps to reproduce the behavior:

  • Compile any React 17 web project

Expected behavior

The compilation process fails and throws an exception :

Failed to compile. TypeError: this.getOptions is not a function

This unexpected behavior appeared right after upgrading to v6.0.0, it is most likely related to an incompatibility issue with the 3.0.0+ version of loader-utils which brought the following breaking change :

removed getOptions in favor loaderContext.getOptions (loaderContext is this inside loader function), 
note - special query parameters like ?something=true is not supported anymore, 
if you need this please do it on loader side, but we strongly recommend avoid it, as alternative you can use ?something=1 and handle 1 as true

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions