Reputation: 687
I am try to using SVG Icon as React component with svgr
everything works well. I can imoport SVG and svgr convert it to ReactComponents perfectly.
but, My IDE webstorm still shows me error when I import svg like below
I am using typescript and nextjs as well.
what is real problem? is it only caused by IDE? or Should I setup additional options?
here is my config files
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": "src/"
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.svg"
]
}
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
config.module.rules.push({
test: /\.svg$/,
use: [{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: {
removeViewBox: false
}
}
}
}],
})
return config
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
return config
},
}
and no babelrc because I am using default babel setting given by nextjs.
Thanks in advance
Upvotes: 0
Views: 1234
Reputation: 687
I find by my self. It is caused by typescript. i had to declare type for .svg
I made typing.d.ts file on the root
declare module '*.svg' {
import * as React from 'react';
export const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
const src: string;
export default src;
}
The IDE does not show error any more
Upvotes: 3