Closed Moranilt closed 2 years ago
This is because you are probably using a non-default SVG loader.
Please see previous related issues/comments:
https://github.com/vercel/next.js/pull/36907#pullrequestreview-973625856 https://github.com/vercel/next.js/issues/35634#issuecomment-1080942525
Currently running into the same issue, I'm using SVGR and have it configured in my webpack but thats about it. I import the SVGs as react components. Is SVGR not a default SVG loader? What is the proper way to do this?
Please see the above comments. There is a workaround suggestion.
Currently running into the same issue, I'm using SVGR and have it configured in my webpack but thats about it. I import the SVGs as react components. Is SVGR not a default SVG loader? What is the proper way to do this?
@liamlows The solution that worked for me is to replace default SVG-files with ReactComponents that render the SVG-code. SVG-files have been coverted to ReactComponents.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 Binaries: Node: 16.13.0 npm: 8.10.0 Yarn: N/A pnpm: N/A Relevant packages: next: 12.1.6 react: 17.0.2 react-dom: 17.0.2
What browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
next start
Describe the Bug
I was updating my packages and I wanted to upgrade NextJS version. But after upgrade I've got test errors, a bit strange errors, like:
Check the render method of styled(Icon)
. I thought that I had an issue with styled-components plugin, but this decision was incorrect.Later I found out that the reason was SVG-imports that was working with version 12.1.0 but not 12.1.1 and greater only in Jest tests.
Expected Behavior
Expected Jest tests to work with NextJS 12.1.1 or greater and SVG imports with
babel-plugin-inline-react-svg
. It was working with NextJS v12.1.0 or lower.To Reproduce
To reproduce it you should create a test and Import any SVG-file using
babel-plugin-inline-react-svg
and following dependencies:.babelrc:
jest.config.json:
jest.setup.js:
tsconfig.json:
You should use your SVG-file as Component to reproduce this bug. With this code I'm getting an error:
Write any simple test and run it with
jest --watch
. You will get an error like this: