Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How to render SVGs coming from api response using next/image or <img> in Next.js?

I've got a bunch of svgs coming from an api response, which I get inside useEffect. Response looks like this

{svg1: 'https://remoteserver.com/assests/svg1.svg', ...and so on}

( These svgs aren't static coming from /public folder. So I don't import them at top.) I want to render them in nextjs using next/image or normal <img> tag, passing the url into src. I know that next.js by default don't support svgs.

 <Image alt='SVG from api'
        src={response.svg1}
        width={'45px'}
        height={'45px'}
        objectFit='contain' />

According to docs, this is possible with dangerouslyAllowSVG, but there is security risk here, so I don't want to go this route. I know packages like SVGR and babel-inline-svg are there to solve the issue, but they are for using svgs as react components. I've also tried next-images and made use of withImages inside next.config.js.

const withImages = require('next-images')
module.exports = withImages({
     reactStrictMode: true,
     env: {
        BASE_URL: process.env.BASE_URL
        },
     images: {
      domains: ['remoteserver.com', 'remoteserver2.com']
      },
  webpack(config, options) {
    return config
  }
})

But the build is failing when I try next build.

./static/images/Logo.png
TypeError: unsupported file type: undefined (file: undefined)

What am I missing/doing wrong here ? Are there any alternate solutions ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So apparantly I went with dangerouslyAllowSVG and added the CSP headers. Still svg wasn't loading with <Image /> from next/image. It worked when I used normal <img> tag though. Not sure if this is the best fix though :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!