mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
2.5 KiB
2.5 KiB
| title |
|---|
| Common Errors | Guide |
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 you rely on
baseUrlin yourtsconfig.json. Vite doesn't take into accounttsconfig.jsonby default, so you might need to installvite-tsconfig-pathsyourself, if you rely on this behaviour.
- It's possible that you rely on
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:
- 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.
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
alias: {
'@/': './src/', // [!code --]
'@/': new URL('./src/', import.meta.url).pathname, // [!code ++]
}
}
})
Failed to terminate worker
This error can happen when NodeJS's fetch is used with default pool: 'threads'. This issue is tracked on issue Timeout abort can leave process(es) running in the background #3077.
As work-around you can switch to pool: 'forks' or pool: 'vmForks'.
::: code-group
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
pool: 'forks',
},
})
vitest --pool=forks
:::
Segfaults and native code errors
Running native NodeJS modules in pool: 'threads' can run into cryptic errors coming from the native code.
Segmentation fault (core dumped)thread '<unnamed>' panicked at 'assertion failedAbort trap: 6internal error: entered unreachable code
In these cases the native module is likely not built to be multi-thread safe. As work-around, you can switch to pool: 'forks' which runs the test cases in multiple node:child_process instead of multiple node:worker_threads.
::: code-group
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
pool: 'forks',
},
})
vitest --pool=forks
:::