unplugin-icons: vue-tsc Cannot find module '~icons/ui/info' or its corresponding type declarations.
In our project running Vite and Vue2 (through vue-demi), when running vue-tsc
, we get an error:
ERROR(vue-tsc) Cannot find module '~icons/ui/info' or its corresponding type declarations.
tsconfig:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"sourceMap": true,
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types",
"./node_modules/unplugin-icons/types"
],
"paths": {
"@/*": ["src/*"]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"src/**/*.d.ts",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
],
"vueCompilerOptions": {
"experimentalCompatMode": 2
}
}
vite.config:
const config = defineConfig(({ mode }) => {
const isProduction = mode === "production";
return {
resolve: {
alias: {
"@": path.resolve(__dirname, "src")
},
dedupe: ["vue-demi"]
},
build: {
minify: isProduction,
manifest: true,
rollupOptions: {
input: "src/main.ts"
}
},
plugins: [
legacy({
targets: ["ie >= 11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
}),
Vue2(),
checker({
vueTsc: true
}),
Icons({
compiler: "vue2",
customCollections: {
"ui": FileSystemIconLoader(
"./src/assets/icons/ui")
}
})
],
server: {
port: 3333
}
};
});
Icon is src/assets/icons/ui/info.svg
with the following svg-code:
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 10C0 4.47715 4.47715 0 10 0C15.5228 0 20 4.47715 20 10C20 15.5228 15.5228 20 10 20C4.47715 20 0 15.5228 0 10Z" fill="currentColor"/>
<path d="M10.47 14.1498C10.46 14.1998 10.455 14.2648 10.455 14.3448C10.455 14.5848 10.545 14.7048 10.725 14.7048C10.805 14.7048 10.89 14.6798 10.98 14.6298C11.08 14.5798 11.22 14.4948 11.4 14.3748L11.595 14.8848C11.425 15.1148 11.16 15.3498 10.8 15.5898C10.45 15.8298 10.005 15.9498 9.465 15.9498C9.005 15.9498 8.645 15.8648 8.385 15.6948C8.135 15.5148 8.01 15.2848 8.01 15.0048C8.01 14.9448 8.015 14.8948 8.025 14.8548L8.415 11.8998L8.835 8.7648L7.995 8.3148L8.115 7.6698L11.01 7.2798L11.4 7.4598L10.47 14.1498ZM10.455 5.9898C10.155 5.9898 9.885 5.8698 9.645 5.6298C9.415 5.3898 9.3 5.1198 9.3 4.8198C9.3 4.4098 9.44 4.0648 9.72 3.7848C10 3.4948 10.37 3.3498 10.83 3.3498C11.18 3.3498 11.46 3.4648 11.67 3.6948C11.88 3.9248 11.985 4.1898 11.985 4.4898C11.985 4.9298 11.855 5.2898 11.595 5.5698C11.335 5.8498 10.955 5.9898 10.455 5.9898Z" fill="#113053"/>
</svg>
I’ve see an other issue that says to add “skipLibCheck: true” to tsconfig, but this has not worked.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 20 (2 by maintainers)
Commits related to this issue
- fix: https://github.com/antfu/unplugin-icons/issues/204 — committed to youlaitech/vue3-element-admin by haoxianrui a year ago
- fix: https://github.com/antfu/unplugin-icons/issues/204 Former-commit-id: 0d88fac3c1089e4464d864da97b536b74df6c3d9 — committed to youlaitech/vue3-element-admin by haoxianrui a year ago
Update for Nuxt users
The following entry in
nuxt.config
removed the import errors:Update
I was able to get this to work by replacing
~icons/
withvirtual:icons/
when referencing an icon・・・・・・
I’m experiencing this only in production with SvelteKit/Vite deploying to Vercel. My
global.d.ts
file has this line:and this is the error thrown when trying to build:
Everything works perfectly in development.
We temporarily close this due to the lack of enough information. Please provide a minimal reproduction to reopen the issue. Thanks.
The same problem has been solved with the following solution:
in
tsconfig.json
.@antfu, any help with this one? 🙏
Hi @Nacho114 I actually was able to do it on SvelteKit.
Here was my solution: https://github.com/unplugin/unplugin-icons/issues/128#issuecomment-1675830394
Also prepped a CodeSandbox for you here. While checking it, here are a few things to note:
vite.config.ts
tsconfig.json
Usual workflow when importing a new icon.
@amirhoseinsalimi It works if you use auto-import. https://github.com/antfu/unplugin-icons#auto-importing https://github.com/antfu/unplugin-icons#use-with-resolver
I’ll leave this issue open, since i feel it should either documented that this is necessary or should be fixed
Hey!
Thanks for the quick answer 😃
So I followed steps 1 and 2.
The main difference is that:
In
src/app.d.ts
I haveimport 'unplugin-icons/types/svelte';
And I added all icons already
"@iconify/json": "^2.2.123"
in the package.jsonBut I do still get the type error:
import ChevronRight from 'virtual:icons/gg/chevron-right';
I tried to replace virtual:icons with ~icons but with the same result 😕
two way to fix it
in
nuxt.config.ts
then the
./.nuxt/tsconfig.json
will add it intype
property.now it can work well.
another way is that write a d.ts and add
/// <reference types="unplugin-icons/types/vue" />
in the top.it also can work well.
hope these way can help you. 😃