vite-plugin-svgr
vite-plugin-svgr copied to clipboard
Cannot build with default export and typescript
Hello 👋,
When using default export, and running vite build
, I got this error :
error TS2322: Type '{ class: string; }' is not assignable to type 'IntrinsicAttributes'.
Property 'class' does not exist on type 'IntrinsicAttributes'.
I do not have this error when running dev server / or using named imports. I am running Preact.
// tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",
"baseUrl": ".",
"types": [
"vite/client",
"vite-plugin-svgr/client"
],
"paths": {
"@/*" : ["src/*"],
"react": ["./node_modules/preact/compat/"],
"react-dom": ["./node_modules/preact/compat/"]
},
"typeRoots": ["node_modules/@types", "src/@types"],
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
// vite.config.ts
plugins: [
preact(),
svgr({
exportAsDefault: true,
svgrOptions: {
svgoConfig: {
prefixIds: false
}
}
}),
],
// svg.d.ts
/// <reference types="vite-plugin-svgr/client" />
declare module "*.svg" {
const content: any;
export default content;
}
see here 44
Add the following to your tsconfig:
{
"compilerOptions": {
"types": ["vite/client", "vitest/globals", "vite-plugin-svgr/client"],
}
}
}