svgr: import xx from 'path/xx.svg' Error

test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: [ { loader: '@svgr/webpack', options: { icon: true } } ] image

import logoSvg from 'paths/logo.svg';

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

you need to add a svg.d.ts to your project like this:

declare module '*.svg' {
  import { FunctionComponent, SVGProps } from 'react';
  const _: FunctionComponent<SVGProps<HTMLOrSVGElement>>;
  export = _;
}

and it should work as expected (although I’m not sure if the props will actually be passed down to the SVG that is about to be inlined, if it doesn’t, change SVGProps to any)

So - you don’t need to compile it to typescript if you are using webpack-loader - for TS it still SVG and nothing more.

It worth to use only if you are pre-compiling these images.