Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda