{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/moduleRunner/nativeModuleMocker.ts#L267-L291","documentation":"Native (Node-level) module mocking of TypeScript files requires `module.stripTypeScriptTypes`, which landed in Node.js 22.15. When the mocker receives a module whose format includes `typescript` and `module.stripTypeScriptTypes` is undefined, this error fires before any parsing attempt. The check is at nativeModuleMocker.ts:283-286.","triggerScenarios":"Calling `vi.mock` (automock, autospy, or manual) on a `.ts`/`.mts`/`.cts` module while running Vitest on Node.js < 22.15. The `transformCode` function detects `format.includes('typescript')` and finds no `stripTypeScriptTypes`.","commonSituations":"CI image pinned to Node 20 or 22.0-22.14; local dev on an older Node LTS; a Node version manager pointing at the wrong runtime; native ESM mocking enabled (which routes through the native mocker rather than the Vite-transformed path).","solutions":["Upgrade Node to 22.15 or newer (or any supported 24+).","If you cannot upgrade Node, run the affected tests through the Vite-transformed mocker (disable native ESM mocking / ensure the module goes through Vite's TS plugin).","Convert the mocked module's source to plain JavaScript so `stripTypeScriptTypes` is not needed.","Pin the project's `engines.node` to `>=22.15` so the mismatch fails early at install."],"exampleFix":"// before - .nvmrc\n20.18.0\n\n// after\n22.15.0","handlingStrategy":"validation","validationCode":"import module from 'node:module'; if (typeof module.stripTypeScriptTypes !== 'function' && isTsFile(filename)) throw new Error('upgrade Node to >=22.15 to mock TS modules natively')","typeGuard":"function supportsStripTypeScriptTypes(): boolean { return typeof (require('node:module') as any).stripTypeScriptTypes === 'function' }","tryCatchPattern":"null","preventionTips":["Run Vitest on Node >= 22.15 (set `.nvmrc` and `engines.node`).","In CI matrices, gate native-TS-mocking tests on the Node version.","Keep a plain-JS build of modules you need to mock on older Node."],"tags":["mocker","typescript","node-version","strip-typescript-types"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}