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

🐛 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:

https://github.com/gregberge/svgr/blob/81369db030cf9498c4438a9273816f3dd5a673f6/packages/webpack/src/index.ts#L58-L71

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I have exact same problem. Going back to 5.5.0 fixed it for now.

I had the same issue here while trying to use svgr with @storybook/react@^6.4.9. The storybook’s docs said it fully upgraded to webpack@5 , but I still see webpack@4 references in my .lock file

Can be solved by forcing storybook to use webpack 5: https://storybook.js.org/blog/storybook-for-webpack-5/

Hello @gregberge , I finally understood what was going on. create-react-app, which is used to compile React apps, is using webpack 4 behind the scene, so even if I had webpack 5 dependency explicitly set on my own package.json, it was not used during the compilation. I had to upgrade create-react-app to @next which is being developed upon webpack 5. The final word is svgr is perfectly fine and we can definitely close this issue.

Hello, the new loader is only compatible with webpack 5, please upgrade or stay in v5.x.

Hello @gregberge , Actually I’m already using Webpack 5 : npm view webpack :

image

Good to hear, thanks!

Hello, the new loader is only compatible with webpack 5, please upgrade or stay in v5.x.