question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVG error when using nx with next-images

See original GitHub issue

Current Behavior

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

Environment

Mac catalina, node 12

Workaround

This workaround works, just looks kind of ugly

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kirjaicommented, Mar 26, 2021

We use nx since 9.x

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 👍

1reaction
kirjaicommented, Mar 26, 2021

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 whatever next-images is trying to do. you can still use svgr and next-images side by side, with some workarounds i mentioned in the previous comment. but your request to be able to use next-images exclusively is definitely valid, as we don’t want to lock users into such decisions

Now, 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 in withNx.

As a side note, I noticed that in your repro repo, you’re not using withNx, which we actually advise against. If you have specific reasons you’re not using withNx, we’d like to know them, so we can address and fix them

We’ll start working on this soon

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found