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

Problem with SVG sprite in 2.0 #47

Closed
tizzle opened this issue Dec 7, 2018 · 3 comments
Closed

Problem with SVG sprite in 2.0 #47

tizzle opened this issue Dec 7, 2018 · 3 comments

Comments

@tizzle
Copy link

tizzle commented Dec 7, 2018

When importing my SVG as sprites like this:

import React from 'react';
import MyIcon from './icons/my-icon.svg?sprite';

export default () => (
  <div>
    my page..
    <MyIcon />
  </div>
);

i run into the following error:

 ERROR  Failed to compile with 1 errors                                                                     17:01:33

 error  in ./assets/icons/search.svg?sprite

Module build failed (from ./node_modules/svg-sprite-loader/lib/loader.js):
InvalidSvg: svg-sprite-loader exception.

module.exports = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMjRweCIgaGVpZ2h0PSIyNHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogU2tldGNoIDUyLjMgKDY3Mjk3KSAtIGh0dHA6Ly93d3cuYm9oZW1pYW5jb2RpbmcuY29tL3NrZXRjaCAtLT4KICAgIDx0aXRsZT5pY29uLXNlYXJjaDwvdGl0bGU+CiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz4KICAgIDxnIGlkPSJpY29uLXNlYXJjaCIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+CiAgICAgICAgPHBhdGggZD0iTTE1LjMxMzQ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E1LjUzODQ2MTUgNy43MTM3MzA3NywxNS4wMDIzODQ2IDYuNzQwMzA3NjksMTQuMDI4OTIzMSBDNS43NjY4NDYxNSwxMy4wNTU1IDUuMjMwNzY5MjMsMTEuNzYxMjY5MiA1LjIzMDc2OTIzLDEwLjM4NDYxNTQgWiIgaWQ9IkltcG9ydGVkLUxheWVycyIgZmlsbD0iIzAwMDAwMCI+PC9wYXRoPgogICAgPC9nPgo8L3N2Zz4="
    at Object.loader (/Users/tillhinrichs/Documents/_DEVELOPER/HTML/CleanCleanShop/cc-next2/node_modules/svg-sprite-loader/lib/loader.js:29:11)

 @ ./components/header/searchBox/index.js 5:0-58 6:24-27
 @ ./components/header/index.js
 @ ./pages/_app.js
 @ multi ./pages/_app.js

The source of this error is the (rather smallish) SVG being converted to Base64 before handed over to svg-sprite-loader. I think it would help to always turn of BASE64 conversion for elements having the ?sprite suffix. Is that possible?

@cyrilwanner
Copy link
Owner

Hi @tizzle
It should already be the case, that SVG elements don't get base64 encoded when used as a sprite.
I just tried your image (just decoded the base64 string) and also other smaller SVG elements in an empty project with the default config and I didn't get this error.
Do you overwrite a default config or maybe have other plugins or loaders which could handle SVG images?
If you don't have something confidential in your next.config.js, it would maybe help if you can post it here. Thank you!

@tizzle
Copy link
Author

tizzle commented Dec 8, 2018

Hey @cyrilwanner,

after some investigation i found i was a bit trigger-happy with this bug report. It turns out that i updated next-optimized-images and next-fonts as well. As it turned out next-fonts added the possibility to use SVG fonts now, which breaks next-optimized-images. I will file an issue over at next-fonts.

Feel free to close.

Thanks for your fast reply and the great plugin!

Edit: Issue at next-fonts: rohanray/next-fonts#6

@cyrilwanner
Copy link
Owner

That's good to know, thank you for creating the issue in next-fonts! It looks like they already added an option to disable SVG fonts.

I'll close this issue for now, but feel free to open a new one when you are experiencing another problem.

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

No branches or pull requests

2 participants