Common Errors
Cannot find module './relative-path'
If you receive an error that module cannot be found, it might mean several different things:
- You misspelled the path. Make sure the path is correct.
- It's possible that your rely on
baseUrl
in yourtsconfig.json
. Vite doesn't take into accounttsconfig.json
by default, so you might need to installvite-tsconfig-paths
yourself, if you rely on this behaviour.
- It's possible that your rely on
ts
import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
export default defineConfig({
plugins: [tsconfigPaths()]
})
import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
export default defineConfig({
plugins: [tsconfigPaths()]
})
Or rewrite your path to not be relative to root:
diff
- import helpers from 'src/helpers'
+ import helpers from '../src/helpers'
- import helpers from 'src/helpers'
+ import helpers from '../src/helpers'
- Make sure you don't have relative aliases. Vite treats them as relative to the file where the import is instead of the root.
diff
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
alias: {
- '@/': './src/',
+ '@/': new URL('./src/', import.meta.url).pathname,
}
}
})
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
alias: {
- '@/': './src/',
+ '@/': new URL('./src/', import.meta.url).pathname,
}
}
})