diff --git a/docs/guide/common-errors.md b/docs/guide/common-errors.md index 47f40e9fb..f6cb04acc 100644 --- a/docs/guide/common-errors.md +++ b/docs/guide/common-errors.md @@ -43,21 +43,6 @@ export default defineConfig({ }) ``` -## Cannot mock "./mocked-file.js" because it is already loaded - -This error happens when `vi.mock` method is called on a module that was already loaded. Vitest throws this error because this call has no effect since cached modules are preferred. - -Remember that `vi.mock` is always hoisted - it means that the module was loaded before the test file started executing - most likely in a setup file. To fix the error, remove the import or clear the cache at the end of a setup file - beware that setup file and your test file will reference different modules in that case. - -```ts [setupFile.js] -import { vi } from 'vitest' -import { sideEffect } from './mocked-file.js' - -sideEffect() - -vi.resetModules() -``` - ## Failed to terminate worker This error can happen when NodeJS's `fetch` is used with default [`pool: 'threads'`](/config/#threads). This issue is tracked on issue [Timeout abort can leave process(es) running in the background #3077](https://github.com/vitest-dev/vitest/issues/3077).