SVG error when using nx with next-images
See original GitHub issueCurrent Behavior
SVG can not show properly when using nx with next-images
Expected Behavior
SVG shown
Steps to Reproduce
See: https://github.com/zhangciwu/nx-next-svg-error-repo Digest:
import compass from './compass.svg';
export function Index() {
return (
<div className={styles.page}>
<h2>Error of SVG: the below svg can not show properly</h2>
<img src={compass}/>
</div>
);
}
next.config.js:
const withImages = require('next-images');
const withPlugins = require('next-compose-plugins');
module.exports = withPlugins(
[
[
withImages,
{
inlineImageLimit: 2048
}
]
// other plugins
],
{}
);
Failure Logs
No log
The svg file got wrapped in js in dist:
Environment
Mac catalina, node 12
Workaround
This workaround works, just looks kind of ugly
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Can't import SVG into Next.js - Stack Overflow
You need to provide a webpack loader that will handle SVG imports, one of the famous one is svgr. In order to configure...
Read more >Adding Images, Fonts, and Files - Nx
Adding SVGs. SVG images can be imported using the method described above. Alternatively, you can import SVG images as React components.
Read more >Using Next.js with Expo for Web
Using Expo with Next.js means you can share all of your existing components ... <Image /> components or use react-native-svg then you can...
Read more >How to Build Scalable Architecture for your Next.js Project
We would like for all developers working on this project to use the ... is a warning and 2 is an error in...
Read more >How To Combine And Use Multiple NextJS Plugins
Another thing to pay attention to is the configuration objects we passed to our next-react-svg and next-images plugins. We don't want next-images to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
right, that explains it then. yeah, the documentation sounds like the one you found already (link). Probably shouldn’t be in the “Deploying to Vercel” section, you’re right. It started out as a deployment-only thing, but has grown in usefulness since. I’ll make a note to address this 👍
right, i see. so i don’t think there’s any other workaround other than the one you linked to.
for reference (i know you’re already aware of this, but worth mentioning for anyone else stumbling upon this). the reason for the issue is that in the webpack config we use, we use
svgr
to allow users to import SVGs as react components. That interferes with whatevernext-images
is trying to do. you can still usesvgr
andnext-images
side by side, with some workarounds i mentioned in the previous comment. but your request to be able to usenext-images
exclusively is definitely valid, as we don’t want to lock users into such decisionsNow, there’s no official / supported way to disable
svgr
as of right now. so, what we’re considering doing is allowing users to disable it via a new flag inwithNx
.We’ll start working on this soon