Skip to content
Advertisement

How to import SVG into Next.js component?

I am trying to import an SVG image from file into a Next.js component.

In the assets folder I have google.svg (icon):

JavaScript

I need to import that SVG inside of this inside of the Next.js component:

JavaScript

I installed this package: https://www.npmjs.com/package/next-images

and set configuration based on that documentation in next.config.js:

JavaScript

Why my import of SVG does not work?

Advertisement

Answer

Another approach would be to make a component for your svg. I like this approach because I can easily pass in props for width, height color etc if required on the svg.

JavaScript

and in your file from above.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement