{"id":"989009ec131275ae","repo":"vitest-dev/vitest","slug":"unknown-mock-type-mock-as-any-type","errorCode":null,"errorMessage":"Unknown mock type: ${(mock as any).type}","messagePattern":"Unknown mock type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mocker/src/browser/interceptor-msw.ts","lineNumber":109,"sourceCode":"      const worker = setupWorker(\n        http.get(/.+/, async ({ request }) => {\n          const path = cleanQuery(request.url.slice(location.origin.length))\n          if (!this.mocks.has(path)) {\n            return passthrough()\n          }\n\n          const mock = this.mocks.get(path)!\n\n          switch (mock.type) {\n            case 'manual':\n              return this.resolveManualMock(mock)\n            case 'automock':\n            case 'autospy':\n              return Response.redirect(injectQuery(path, `mock=${mock.type}`))\n            case 'redirect':\n              return Response.redirect(mock.redirect)\n            default:\n              throw new Error(`Unknown mock type: ${(mock as any).type}`)\n          }\n        }),\n      )\n      return worker.start(this.options.mswOptions).then(() => worker)\n    }).finally(() => {\n      this.worker = worker\n      this.startPromise = undefined\n    })\n    return await this.startPromise\n  }\n}\n\nconst trailingSeparatorRE = /[?&]$/\nconst timestampRE = /\\bt=\\d{13}&?\\b/\nconst versionRE = /\\bv=\\w{8}&?\\b/\nfunction cleanQuery(url: string) {\n  return url.replace(timestampRE, '').replace(versionRE, '').replace(trailingSeparatorRE, '')\n}","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/mocker/src/browser/interceptor-msw.ts#L91-L127","documentation":"Thrown at packages/mocker/src/browser/interceptor-msw.ts:109 as the default case of the switch over mock.type inside the MSW request handler. The interceptor handles four known types (manual, automock, autospy, redirect); any other value means the registry produced a module with an unrecognized type, which is an internal contract violation.","triggerScenarios":"A MockedModule with a type outside the known set reaching the MSW fetch handler at interceptor-msw.ts:100-110. This requires the registry to have registered a module under an unhandled type string, which the public API cannot do.","commonSituations":"Vitest internal regression where a new mock type was added to registry but not to the interceptor switch; version skew between @vitest/mocker builds; corrupted module object in the registry.","solutions":["Reinstall @vitest/mocker and vitest to ensure consistent internal types.","Open a Vitest issue with a reproduction as the error indicates an unhandled internal state.","Avoid custom forks/patches of the mocker registry that introduce new type values."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Internal state error; user code cannot pre-validate the mock type.\n// Catch to surface and report.\ntry {\n  // test code that triggers MSW interceptor mocking\n} catch (e) {\n  if (e instanceof Error && /Unknown mock type/.test(e.message)) {\n    console.error('Vitest internal: unrecognized mock type in MSW interceptor. Report with reproduction.')\n  }\n  throw e\n}","preventionTips":["Keep @vitest/mocker and vitest on the same version.","Avoid patching the mocker registry or interceptor with custom types.","Reinstall packages after version bumps."],"tags":["msw","interceptor","internal","browser-mocking"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}