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

[next-image-loader] "TypeError: Invalid SVG" when importing SVG sprites #26176

Closed
gdorsi opened this issue Jun 16, 2021 · 5 comments · Fixed by #26281
Closed

[next-image-loader] "TypeError: Invalid SVG" when importing SVG sprites #26176

gdorsi opened this issue Jun 16, 2021 · 5 comments · Fixed by #26281
Labels
bug Issue was opened via the bug report template.

Comments

@gdorsi
Copy link

gdorsi commented Jun 16, 2021

What version of Next.js are you using?

11.0.0

What version of Node.js are you using?

v14.15.1

What browser are you using?

What operating system are you using?

macOS

How are you deploying your application?

Other platform

Describe the Bug

When a svg sprite (like this one) is imported "TypeError: Invalid SVG" is thrown on build.

Expected Behavior

The import should return the StaticImageData with an empty placeholder without throwing an error.

To Reproduce

  1. Start a new next project
  2. Download this image
  3. Import the svg in a javascript module (import logo from "./logo-header.svg")
  4. Run the build with next build
@gdorsi gdorsi added the bug Issue was opened via the bug report template. label Jun 16, 2021
@gdorsi gdorsi changed the title "TypeError: Invalid SVG" when importing SVG sprites [next-image-loader] "TypeError: Invalid SVG" when importing SVG sprites Jun 16, 2021
@Shmoji
Copy link

Shmoji commented Jun 16, 2021

I'm also having issues with importing SVGs. I use babel-plugin-inline-react-svg to load SVGs, but it is no longer allowing the imported SVGs to be used as components in templates after the Next 11 update

@jonathandsouza
Copy link

I think I am having a similar problem with next-optimized-images. The error says
image

@janhuenermann
Copy link

I also have this issue with @svgr/webpack. I got around it by making each SVG file its own React component, i.e.

export const MySVG = ({ ...otherProps }) => (
  <svg {...otherProps}>
  ...
  </svg>
)

Of course, this is not a scalable solution. It would be nice to have proper support for @svgr/webpack or babel-plugin-inline-react-svg.

@styfle
Copy link
Member

styfle commented Jun 17, 2021

Thanks for reporting this issue!

I'm going to close and merge with the similar issue #26130.

@styfle styfle closed this as completed Jun 17, 2021
kodiakhq bot pushed a commit that referenced this issue Jun 18, 2021
This PR does a couple things:

1. Omit svg static imports if the user has defined custom webpack config with svg rule
2. Change TS type to `any` for svg imports to avoid conflicts with other plugins

The idea is that some users want to use `next/image` with static imports for most image types but not for svg and instead inline those images with a plugin.

- Fixes #25950  
- Fixes #26130 
- Fixes #26176 
- Fixes #26196 
- Fixes #26067 


## Bug

- [x] Related issues linked using Fixes #26130 
- [x] Integration tests added
flybayer pushed a commit to blitz-js/next.js that referenced this issue Jun 24, 2021
…6281)

This PR does a couple things:

1. Omit svg static imports if the user has defined custom webpack config with svg rule
2. Change TS type to `any` for svg imports to avoid conflicts with other plugins

The idea is that some users want to use `next/image` with static imports for most image types but not for svg and instead inline those images with a plugin.

- Fixes vercel#25950  
- Fixes vercel#26130 
- Fixes vercel#26176 
- Fixes vercel#26196 
- Fixes vercel#26067 


## Bug

- [x] Related issues linked using Fixes vercel#26130 
- [x] Integration tests added
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants