{"id":"2fbc456f5988a172","repo":"vitest-dev/vitest","slug":"cannot-parse-filename-because-module-stripty-2fbc45","errorCode":null,"errorMessage":"Cannot parse '${filename}' because \"module.stripTypeScriptTypes\" is not supported. Module mocking requires Node.js 22.15 or higher. This is NOT a bug of Vitest.","messagePattern":"Cannot parse '(.+?)' because \"module\\.stripTypeScriptTypes\" is not supported\\. Module mocking requires Node\\.js 22\\.15 or higher\\. This is NOT a bug of Vitest\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/moduleRunner/nativeModuleMocker.ts","lineNumber":285,"sourceCode":"}\n\nlet __require: NodeJS.Require | undefined\nfunction getBuiltinModule(moduleId: string) {\n  __require ??= module.createRequire(import.meta.url)\n  return __require(`${moduleId}?mock=actual`)\n}\n\nfunction genSourceMapUrl(map: SourceMap | string): string {\n  if (typeof map !== 'string') {\n    map = JSON.stringify(map)\n  }\n  return `data:application/json;base64,${Buffer.from(map).toString('base64')}`\n}\n\nfunction transformCode(code: string, format: string, filename: string) {\n  if (format.includes('typescript')) {\n    if (!module.stripTypeScriptTypes) {\n      throw new Error(`Cannot parse '${filename}' because \"module.stripTypeScriptTypes\" is not supported. Module mocking requires Node.js 22.15 or higher. This is NOT a bug of Vitest.`)\n    }\n    return module.stripTypeScriptTypes(code)\n  }\n  return code\n}\n","sourceCodeStart":267,"sourceCodeEnd":291,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/moduleRunner/nativeModuleMocker.ts#L267-L291","documentation":"`transformCode` (`nativeModuleMocker.ts:285`) strips TypeScript types before parsing a module for mocking, using `module.stripTypeScriptTypes` — a Node API added in Node 22.15. On older Node, mocking a `.ts` (or `format` includes `typescript`) module is impossible, and this `Error` is thrown explicitly, clearly stating it is NOT a Vitest bug. Plain JS modules are unaffected.","triggerScenarios":"`vi.mock('./mod.ts')` (automock or manual) running under Node < 22.15 (Node 20.x, early 22.x).","commonSituations":"Local dev or CI on Node 20 LTS; a Docker image pinned to an older Node; an Org policy delaying Node upgrades.","solutions":["Upgrade Node to 22.15+ (or 24+) — Vitest's engines field lists supported versions.","Provide a manual factory so the original TS source isn't parsed: `vi.mock('./mod.ts', () => ({...}))`.","Mock only the compiled JS output instead of the `.ts` source."],"exampleFix":"// before (Node < 22.15)\nvi.mock('./util.ts') // automock — needs stripTypeScriptTypes\n\n// after — manual factory avoids parsing the TS source\nvi.mock('./util.ts', () => ({\n  format: vi.fn(),\n}))","handlingStrategy":"validation","validationCode":"// Detect the Node API before mocking TS modules.\nimport module from 'node:module'\nconst supportsTsStripping = typeof module.stripTypeScriptTypes === 'function'\nif (!supportsTsStripping) {\n  throw new Error('Node < 22.15: use a manual vi.mock factory for TS modules')\n}","typeGuard":null,"tryCatchPattern":"try {\n  vi.mock('./mod.ts')\n} catch (e) {\n  if (e instanceof Error && /stripTypeScriptTypes is not supported/.test(e.message)) {\n    vi.mock('./mod.ts', () => ({ /* explicit stubs */ }))\n  } else throw e\n}","preventionTips":["Run Node 22.15+ (or 24+) for TypeScript module mocking.","On older Node, always provide a manual vi.mock factory for TS modules.","Pin the Node version in CI/Docker to match Vitest's requirements."],"tags":["mocking","typescript","node-version","configuration","native-mocker"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}