vite-plugin-svgr icon indicating copy to clipboard operation
vite-plugin-svgr copied to clipboard

Cannot build with default export and typescript

Open dolie opened this issue 2 years ago • 2 comments

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;
}

dolie avatar Oct 27 '22 10:10 dolie

see here 44

panjiangyi avatar Jan 31 '23 02:01 panjiangyi

Add the following to your tsconfig:

{
  "compilerOptions": {
    "types": ["vite/client", "vitest/globals", "vite-plugin-svgr/client"],
    }
  }
}

spoilerdo avatar Aug 14 '23 08:08 spoilerdo