{"id":"10f9641c4c4a4c72","repo":"vitest-dev/vitest","slug":"importactual-is-not-implemented","errorCode":null,"errorMessage":"importActual is not implemented","messagePattern":"importActual is not implemented","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/moduleRunner/bareModuleMocker.ts","lineNumber":288,"sourceCode":"    else if (mockType === 'autospy') {\n      registry.register('autospy', originalId, id, url)\n    }\n    else {\n      const redirect = this.findMockRedirect(id, external)\n      if (redirect) {\n        registry.register('redirect', originalId, id, url, redirect)\n      }\n      else {\n        registry.register('automock', originalId, id, url)\n      }\n    }\n\n    // every time the mock is registered, we remove the previous one from the cache\n    this.invalidateModuleById(id)\n  }\n\n  async importActual<T>(_rawId: string, _importer: string, _callstack?: string[] | null): Promise<T> {\n    throw new Error(`importActual is not implemented`)\n  }\n\n  async importMock<T>(_rawId: string, _importer: string, _callstack?: string[] | null): Promise<T> {\n    throw new Error(`importMock is not implemented`)\n  }\n\n  public queueMock(\n    id: string,\n    importer: string,\n    factoryOrOptions?: MockFactory | MockOptions,\n  ): void {\n    const mockType = getMockType(factoryOrOptions)\n    BareModuleMocker.pendingIds.push({\n      action: 'mock',\n      id,\n      importer,\n      factory: typeof factoryOrOptions === 'function' ? factoryOrOptions : undefined,\n      type: mockType,","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/moduleRunner/bareModuleMocker.ts#L270-L306","documentation":"`BareModuleMocker` is the abstract base: it handles mock registration/resolution but does NOT implement actual module loading. Its `importActual` (`bareModuleMocker.ts:288`) unconditionally throws `\"importActual is not implemented\"`. Only the `NativeModuleMocker` subclass (which drives Node's native ESM loader) provides a real `importActual`. Hitting this means the active mocker isn't the native one.","triggerScenarios":"Calling `vi.importActual('mod')` in an environment wired with `BareModuleMocker` — typically the browser pool or a runtime without the native loader hook.","commonSituations":"Running mocking tests in the browser (Playwright/WebDriverIO) where native import isn't available; a workspace/child process using the bare mocker; misconfigured environment.","solutions":["Run the affected test in the Node environment (`// @vitest-environment node`) where `NativeModuleMocker` is used.","Avoid `vi.importActual` in browser tests; restructure mocks so the real module isn't needed.","Use a manual factory (`vi.mock('mod', () => realish)` ) that doesn't require loading the actual module."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Detect whether the native mocker is available before relying on importActual.\n// In browser/worker pools the bare mocker is used and importActual throws.\nconst isNode = typeof process !== 'undefined' && process.versions?.node\nif (!isNode) {\n  throw new Error('vi.importActual is unavailable in this environment')\n}\nconst actual = await vi.importActual('mod')","typeGuard":null,"tryCatchPattern":"try {\n  return await vi.importActual('mod')\n} catch (e) {\n  if (e instanceof Error && /importActual is not implemented/.test(e.message)) {\n    // provide a manual factory instead, or move test to node env\n  }\n  throw e\n}","preventionTips":["Run tests that use vi.importActual in the Node environment (@vitest-environment node).","Avoid vi.importActual in browser tests.","Prefer vi.mock with an explicit factory that doesn't need the real module."],"tags":["mocking","import-actual","environment","browser","not-implemented"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}