{"id":"c814e7fa17d9c3ac","repo":"vitest-dev/vitest","slug":"cannot-parse-url-because-module-striptypescr","errorCode":null,"errorMessage":"Cannot parse '${url}' because \"module.stripTypeScriptTypes\" is not supported. TypeScript coverage requires Node.js 22.15 or higher. This is NOT a bug of Vitest.","messagePattern":"Cannot parse '(.+?)' because \"module\\.stripTypeScriptTypes\" is not supported\\. TypeScript coverage requires Node\\.js 22\\.15 or higher\\. This is NOT a bug of Vitest\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/coverage.ts","lineNumber":743,"sourceCode":"\n  // TODO: should this be abstracted in `project`/`vitest` instead?\n  // if we decide to keep `viteModuleRunner: false`, we will need to abstract transformation in both main thread and tests\n  // custom --import=module.registerHooks need to be transformed as well somehow\n  async transformFile(url: string, project: TestProject, viteEnvironment: string, isTransformedByVite = true): Promise<TransformResult | null | undefined> {\n    const config = project.config\n\n    // vite is disabled, should transform manually if possible\n    if (config.experimental.viteModuleRunner === false || !isTransformedByVite) {\n      const pathname = url.split('?')[0]\n      const filename = pathname.startsWith('file://') ? fileURLToPath(pathname) : pathname\n      const extension = path.extname(filename)\n      const isTypeScript = extension === '.ts' || extension === '.mts' || extension === '.cts'\n      if (!isTypeScript) {\n        const code = await fs.readFile(filename, 'utf-8')\n        return { code, map: null }\n      }\n      if (!module.stripTypeScriptTypes) {\n        throw new Error(`Cannot parse '${url}' because \"module.stripTypeScriptTypes\" is not supported. TypeScript coverage requires Node.js 22.15 or higher. This is NOT a bug of Vitest.`)\n      }\n      const isTransform = process.execArgv.includes('--experimental-transform-types')\n        || config.execArgv.includes('--experimental-transform-types')\n        || process.env.NODE_OPTIONS?.includes('--experimental-transform-types')\n        || config.env?.NODE_OPTIONS?.includes('--experimental-transform-types')\n      const code = await fs.readFile(filename, 'utf-8')\n      return {\n        // `transform` mode will inject source maps comment at the end\n        code: module.stripTypeScriptTypes(code, { mode: isTransform ? 'transform' : 'strip' }),\n        map: null,\n      }\n    }\n\n    return project.vite.environments[viteEnvironment].transformRequest(url)\n  }\n\n  createUncoveredFileTransformer(ctx: Vitest) {\n    const projects = new Set([","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/coverage.ts#L725-L761","documentation":"When instrumenting TypeScript files for coverage, vitest strips types via Node's module.stripTypeScriptTypes (coverage.ts:743). That API only exists in Node.js 22.15+, so older Node crashes here. The error message is explicit that this is an environment limitation, not a vitest bug.","triggerScenarios":"Running vitest coverage over .ts/.mts/.cts files with coverage enabled on a Node.js version older than 22.15.","commonSituations":"CI pinned to Node 20 LTS; local dev on Node 18/20; upgrading vitest without upgrading Node.","solutions":["Upgrade Node.js to 22.15 or newer.","Run Node with --experimental-transform-types (and set NODE_OPTIONS accordingly) so stripTypeScriptTypes is available in transform mode.","Downgrade vitest to a version that didn't require stripTypeScriptTypes, or exclude .ts from coverage."],"exampleFix":"// before\n\"engines\": { \"node\": \">=20\" } // CI uses Node 20 -> throws on .ts coverage\n\n// after\n\"engines\": { \"node\": \">=22.15\" }\n// CI image: node:22","handlingStrategy":"validation","validationCode":"import { gte } from 'semver'\nif (gte(process.version, 'v22.15.0') === false) {\n  throw new Error(`TypeScript coverage needs Node >=22.15; current ${process.version}`)\n}","typeGuard":"function supportsStripTypeScriptTypes(): boolean {\n  return typeof (require('node:module') as any).stripTypeScriptTypes === 'function'\n}","tryCatchPattern":null,"preventionTips":["Pin CI Node to 22.15+ when collecting TS coverage.","Gate TS coverage in CI by Node version.","Document the Node version requirement in the repo's engines field."],"tags":["coverage","typescript","node-version","environment"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}