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

import logoSvg from 'paths/logo.svg';
Hello @XianZhengquan, can you please submit a repro example?
Thank. @neoziro Thanks.I will create a new repository on github and put the repo on it.
@neoziro github
https://github.com/XianZhengquan/svgr-webpack-error
It looks like a Typescript issue, help is welcome here. @theKashey maybe π
What should I do?π€π€π€
Probably asking a Typescript user π
God bless!πππ
This has been bothering me.
So - there are only two questions:
3:22 is props>:<, not a valid JS. So you need to specify a loader to handle a result "SVG".
@neoziro I don't understandπ€π€π€
should be like
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [
"ts-loader", // !
{ loader: '@svgr/webpack', options: { icon: true } } // probably with `babel:false`
]
But still the question - why svgr output is in typescript.
Because there is a configuration file .svgrrc.js, the template output is typescript
should be like
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: [ "ts-loader", // ! { loader: '@svgr/webpack', options: { icon: true } } // probably with `babel:false` ]But still the question - why
svgroutput is in typescript.
Can it run normally like this?
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.
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)
Looks like it is solved.
Most helpful comment
you need to add a
svg.d.tsto your project like this: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
SVGPropstoany)