vitest-dev/vitest · error · Error
Cannot parse '${url}' because "module.stripTypeScriptTypes"
Error message
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. What it means
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.
Source
Thrown at packages/vitest/src/node/coverage.ts:743
// TODO: should this be abstracted in `project`/`vitest` instead?
// if we decide to keep `viteModuleRunner: false`, we will need to abstract transformation in both main thread and tests
// custom --import=module.registerHooks need to be transformed as well somehow
async transformFile(url: string, project: TestProject, viteEnvironment: string, isTransformedByVite = true): Promise<TransformResult | null | undefined> {
const config = project.config
// vite is disabled, should transform manually if possible
if (config.experimental.viteModuleRunner === false || !isTransformedByVite) {
const pathname = url.split('?')[0]
const filename = pathname.startsWith('file://') ? fileURLToPath(pathname) : pathname
const extension = path.extname(filename)
const isTypeScript = extension === '.ts' || extension === '.mts' || extension === '.cts'
if (!isTypeScript) {
const code = await fs.readFile(filename, 'utf-8')
return { code, map: null }
}
if (!module.stripTypeScriptTypes) {
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.`)
}
const isTransform = process.execArgv.includes('--experimental-transform-types')
|| config.execArgv.includes('--experimental-transform-types')
|| process.env.NODE_OPTIONS?.includes('--experimental-transform-types')
|| config.env?.NODE_OPTIONS?.includes('--experimental-transform-types')
const code = await fs.readFile(filename, 'utf-8')
return {
// `transform` mode will inject source maps comment at the end
code: module.stripTypeScriptTypes(code, { mode: isTransform ? 'transform' : 'strip' }),
map: null,
}
}
return project.vite.environments[viteEnvironment].transformRequest(url)
}
createUncoveredFileTransformer(ctx: Vitest) {
const projects = new Set([View on GitHub (pinned to d568f8ce37)
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.
Example fix
// before
"engines": { "node": ">=20" } // CI uses Node 20 -> throws on .ts coverage
// after
"engines": { "node": ">=22.15" }
// CI image: node:22 Defensive patterns
Strategy: validation
Validate before calling
import { gte } from 'semver'
if (gte(process.version, 'v22.15.0') === false) {
throw new Error(`TypeScript coverage needs Node >=22.15; current ${process.version}`)
} Type guard
function supportsStripTypeScriptTypes(): boolean {
return typeof (require('node:module') as any).stripTypeScriptTypes === 'function'
} Prevention
- 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.
When it happens
Trigger: Running vitest coverage over .ts/.mts/.cts files with coverage enabled on a Node.js version older than 22.15.
Common situations: CI pinned to Node 20 LTS; local dev on Node 18/20; upgrading vitest without upgrading Node.
Related errors
- Cannot parse '${filename}' because "module.stripTypeScriptTy
- Cannot parse '${filename}' because "module.stripTypeScriptTy
- toHaveFormValues must be called with an object of expected f
- Not called in the browser
- The "${name}" browser provider does not provide a "providerF
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/c814e7fa17d9c3ac.json.
Report an issue: GitHub.