{"id":"ab2ee311224bae86","repo":"vitest-dev/vitest","slug":"mock-id-wasn-t-registered-this-is-probably-a-v","errorCode":null,"errorMessage":"Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.","messagePattern":"Mock (.+?) wasn't registered\\. This is probably a Vitest error\\. Please, open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/browser/mocker.ts","lineNumber":34,"sourceCode":"\n  constructor(\n    private interceptor: ModuleMockerInterceptor,\n    private rpc: ModuleMockerRPC,\n    private createMockInstance: CreateMockInstanceProcedure,\n    private config: ModuleMockerConfig,\n  ) {}\n\n  public async prepare(): Promise<void> {\n    if (!this.queue.size) {\n      return\n    }\n    await Promise.all([...this.queue.values()])\n  }\n\n  public async resolveFactoryModule(id: string): Promise<Record<string | symbol, any>> {\n    const mock = this.registry.get(id)\n    if (!mock || mock.type !== 'manual') {\n      throw new Error(`Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.`)\n    }\n    const result = await mock.resolve()\n    return result\n  }\n\n  public getFactoryModule(id: string): any {\n    const mock = this.registry.get(id)\n    if (!mock || mock.type !== 'manual') {\n      throw new Error(`Mock ${id} wasn't registered. This is probably a Vitest error. Please, open a new issue with reproduction.`)\n    }\n    if (!mock.cache) {\n      throw new Error(`Mock ${id} wasn't resolved. This is probably a Vitest error. Please, open a new issue with reproduction.`)\n    }\n    return mock.cache\n  }\n\n  public async invalidate(): Promise<void> {\n    const ids = Array.from(this.mockedIds)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/browser/mocker.ts#L16-L52","documentation":"Thrown by resolveFactoryModule at packages/mocker/src/browser/mocker.ts:32-35 when the registry has no entry for the id, or the entry is not of type 'manual'. This method resolves a manually-mocked module (one defined via vi.mock with a factory) and expects a ManualMockedModule to already be registered during prepare().","triggerScenarios":"resolveFactoryModule(id) is called for an id that was never queued via queueMock with a factory, or before prepare() finished registering mocks, or after the registry was cleared/reset.","commonSituations":"Vitest internal ordering issue where the factory module is requested before queueMock completed; a reset()/invalidate() clearing the registry mid-run; version mismatch causing the registration path to diverge.","solutions":["Ensure vi.mock(path, factory) was called for the id and that prepare() awaited before resolution.","Avoid manually invoking invalidate()/reset() in a way that clears mocks still in use.","Report with a reproduction as the message flags it as a probable Vitest error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Internal registry error; cannot be pre-validated by user code.\n// Catch to add context and report.\ntry {\n  vi.mock('./x', factory)\n} catch (e) {\n  if (e instanceof Error && /wasn't registered/.test(e.message)) {\n    console.error('Vitest internal: mock factory module not registered. Report with reproduction.')\n  }\n  throw e\n}","preventionTips":["Await prepare() / let Vitest manage mock registration timing.","Avoid calling mocker.invalidate()/reset() mid-test on mocks still in use.","Keep @vitest/mocker and vitest versions aligned."],"tags":["registry","internal","manual-mock","factory"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}