I’m using vite and vitest.
vite.config.ts
export default defineConfig({
plugins: [vue(), VueDevTools()],
resolve: {
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url)),
},
{
find: '@mocks',
replacement: fileURLToPath(new URL('./mock', import.meta.url)),
},
],
},
});
vitest.config.ts
export default mergeConfig(viteConfig, defineConfig({
plugins: [tsconfigPaths()]
}));
tsconfig.app.json
{
"compilerOptions": {
"paths": {
"@/*": ["src/*"],
"@mocks/*": ["mock/*"]
}
}
}
Procject structure
- root
- mock/
- src/
- tests/converter.test.ts
The Alias import works in src/.
Now I have a problem. in converter.test.ts, when I import module with alias, (@/, @mock)
Cannot find module ~~~ or its corresponding type declarations.<< has occured.
Did I missed something?
Environment
vue : 3.4.21
vite : 5.1.6
The test and run serve are working well in Intellij. And when I Crtl + Mouse Left click -> Can go to file.
But the error message is showing and in VSCode test and run serve not work.
bluedot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.