{"record":{"id":"e6a486ab6dc7cd8d","repo":"vitest-dev/vitest","slug":"cannot-parse-filename-because-module-stripty","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/mocker/src/node/parsers.ts","lineNumber":26,"sourceCode":"\nexport async function initSyntaxLexers(): Promise<void> {\n  await Promise.all([\n    initCjsLexer(),\n    initModuleLexer,\n  ])\n}\n\nconst isTransform = process.execArgv.includes('--experimental-transform-types')\n  || process.env.NODE_OPTIONS?.includes('--experimental-transform-types')\n\nexport function transformCode(code: string, filename: string): string {\n  const ext = extname(filename.split('?')[0])\n  const isTs = ext === '.ts' || ext === '.cts' || ext === '.mts'\n  if (!isTs) {\n    return code\n  }\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, { mode: isTransform ? 'transform' : 'strip' })\n}\n\nconst cachedFileExports = new Map<string, string[]>()\n\nexport function collectModuleExports(\n  filename: string,\n  code: string,\n  format: 'module' | 'commonjs',\n  exports: string[] = [],\n): string[] {\n  if (format === 'module') {\n    const [imports_, exports_] = parseModuleSyntax(code, filename)\n    const fileExports = [...exports_.map(p => p.n)]\n    imports_.forEach(({ ss: start, se: end, n: name }) => {\n      const substring = code.substring(start, end).replace(/ +/g, ' ')\n      if (name && substring.startsWith('export *') && !substring.startsWith('export * as')) {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/mocker/src/node/parsers.ts#L8-L44","documentation":"Thrown by `transformCode` in the node-side automock parser when the target file has a TypeScript extension (`.ts`/`.cts`/`.mts`) but `module.stripTypeScriptTypes` is not available on the running Node.js. Automocking a TypeScript module requires stripping its types before parsing, and Vitest delegates this to Node's native `module.stripTypeScriptTypes` API, which was added in Node.js 22.15.0. The message is explicit that this is a Node version limitation, not a Vitest bug.","triggerScenarios":"Automocking (`vi.mock(path)` without a factory) a `.ts`/`.mts`/`.cts` module that contains TypeScript type annotations, while running on Node.js older than 22.15.0. `transformCode` is also invoked transitively when resolving `export *` re-exports during automock analysis.","commonSituations":"CI or local environment pinned to Node 20 LTS or an early Node 22; Docker images using an older `node:22` tag; `engines` in package.json not enforcing the minimum; automocking a TS dependency that itself re-exports from other TS files.","solutions":["Upgrade Node.js to 22.15.0 or newer (the error message states this requirement).","Provide an explicit factory: `vi.mock(path, factory)` to bypass automock's TS-stripping path.","Pin your CI/Docker base image to `node:22.15` or later and update `engines.node` accordingly."],"exampleFix":"// before — automock a TS module on Node < 22.15\nvi.mock('./ts-mod')\n// after — explicit factory avoids transformCode\nvi.mock('./ts-mod', () => ({ fn: vi.fn() }))\n// or: upgrade Node to >= 22.15","handlingStrategy":"validation","validationCode":"// Check Node version before automocking TS modules.\nimport Module from 'node:module'\nfunction canStripTypeScriptTypes(): boolean {\n  return typeof (Module as any).stripTypeScriptTypes === 'function'\n}\nif (!canStripTypeScriptTypes()) {\n  // provide explicit factories, or fail fast with an actionable message\n}","typeGuard":"function nodeSupportsStripTypeScriptTypes(): boolean {\n  return typeof (require('node:module') as any).stripTypeScriptTypes === 'function'\n}","tryCatchPattern":null,"preventionTips":["Pin Node.js to >= 22.15.0 in CI, Docker, and local toolchain.","Set engines.node in package.json to ^22.15.0 || >=22.15.0.","Provide explicit vi.mock factories for TS modules on older Node as a stopgap."],"tags":["automock","typescript","node-version","strip-type-script-types"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}