{"id":"6bb546d1a4acd63a","repo":"vitest-dev/vitest","slug":"vitest-mocker-createmockinstance-is-not-defin","errorCode":null,"errorMessage":"[@vitest/mocker] `createMockInstance` is not defined. This is a Vitest error. Please open a new issue with reproduction.","messagePattern":"\\[@vitest/mocker\\] `createMockInstance` is not defined\\. This is a Vitest error\\. Please open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/automocker.ts","lineNumber":36,"sourceCode":"  object: Record<Key, any>,\n  mockExports: Record<Key, any> = {},\n): Record<Key, any> {\n  const finalizers = new Array<() => void>()\n  const refs = new RefTracker()\n\n  const define = (container: Record<Key, any>, key: Key, value: any) => {\n    try {\n      container[key] = value\n      return true\n    }\n    catch {\n      return false\n    }\n  }\n\n  const createMock = (currentValue: (...args: any[]) => any) => {\n    if (!options.createMockInstance) {\n      throw new Error(\n        '[@vitest/mocker] `createMockInstance` is not defined. This is a Vitest error. Please open a new issue with reproduction.',\n      )\n    }\n    const createMockInstance = options.createMockInstance\n    const prototypeMembers = currentValue.prototype\n      ? collectFunctionProperties(currentValue.prototype)\n      : []\n    return createMockInstance({\n      name: currentValue.name,\n      prototypeMembers,\n      originalImplementation: options.type === 'autospy' ? currentValue : undefined,\n      keepMembersImplementation: options.type === 'autospy',\n    })\n  }\n\n  const mockPropertiesOf = (\n    container: Record<Key, any>,\n    newContainer: Record<Key, any>,","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/automocker.ts#L18-L54","documentation":"Thrown at packages/mocker/src/automocker.ts:36 when mockObject encounters a function-typed export and options.createMockInstance is undefined. The createMockInstance procedure is supplied by the host (ModuleMocker in browser/mocker.ts:155) and is responsible for producing a mock function instance. Its absence means the mocker was constructed or invoked without the procedure wired in, which is an internal contract violation rather than a user API mistake.","triggerScenarios":"Constructing ModuleMocker (or calling mockObject directly) without passing a createMockInstance procedure, then automocking/spying a module that exports a class or function whose prototype has methods. The createMock closure at automocker.ts:34 guards on options.createMockInstance before invoking it.","commonSituations":"Vitest version mismatch between @vitest/mocker and vitest packages; a custom test environment or third-party runner that instantiates ModuleMocker without the procedure; corrupted/partial install where the procedure binding was lost during a refactor.","solutions":["Ensure @vitest/mocker, vitest, and @vitest/spy are on compatible versions (reinstall with pnpm install --force).","If using a custom environment, verify ModuleMocker is constructed with all four constructor args including createMockInstance (browser/mocker.ts:17-22).","Open a Vitest issue with a minimal reproduction as the message requests, since this indicates an internal wiring failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// This is an internal Vitest error; user code cannot pre-validate it.\n// Catch to surface a clearer message and report.\ntry {\n  vi.mock('./someModule') // automock path that triggers createMockInstance\n} catch (e) {\n  if (e instanceof Error && /createMockInstance is not defined/.test(e.message)) {\n    console.error('Vitest internal mocker init failure. Reinstall matching @vitest/* versions and report the issue.')\n  }\n  throw e\n}","preventionTips":["Keep vitest, @vitest/mocker, and @vitest/spy on the same release version.","Reinstall with pnpm install --force after major version bumps.","Avoid custom test environments that bypass ModuleMocker's constructor wiring."],"tags":["automocker","internal","mock-instance","version-mismatch"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}