vitest-dev/vitest · error
Cannot parse ' ' because "module.stripTypeScriptTypes" is…
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 Vite's module runner is disabled for coverage transforms (experimental.viteModuleRunner === false, or the file wasn't transformed by Vite), Vitest falls back to Node's module.stripTypeScriptTypes to strip TS. That API exists only in Node 22.15+, so on older Node processing a .ts/.mts/.cts coverage target it throws — and the message explicitly states this is NOT a Vitest bug.
Solutions
- Upgrade Node to 22.15 or higher (module.stripTypeScriptTypes is available).
- Enable the Vite module runner (remove experimental.viteModuleRunner: false).
- Run Node with --experimental-transform-types (or set NODE_OPTIONS) so the transform mode is available.
- Avoid TypeScript-only coverage in stripped mode on old Node.
Example fix
// before node --version # v20.x -> throws vitest run --coverage // after nvm use 22 # >= 22.15 node --experimental-transform-types ./node_modules/vitest/vitest.mjs run --coverage
Defensive patterns
Strategy: validation
Validate before calling
import { gte } from 'semver'
function nodeSupportsStripTs() {
return typeof require('module').stripTypeScriptTypes === 'function'
|| gte(process.version, 'v22.15.0')
}
// before TS coverage with viteModuleRunner off: if (!nodeSupportsStripTs()) upgrade Node or enable runner Type guard
function supportsStripTypeScriptTypes(): boolean {
return typeof (require('module').stripTypeScriptTypes) === 'function'
} Prevention
- Pin Node >= 22.15 in CI and package.json engines when using TS coverage.
- Don't disable experimental.viteModuleRunner unless Node supports stripTypeScriptTypes.
- Add --experimental-transform-types to execArgv for transform-mode coverage.
When it happens
Trigger: Coverage over TypeScript files with experimental.viteModuleRunner === false (or non-Vite-transformed files) on a Node runtime below 22.15, so module.stripTypeScriptTypes is undefined.
Common situations: Older Node LTS (20.x or early 22); disabling viteModuleRunner for perf/isolation; running TS coverage without --experimental-transform-types.
Related errors
- Cannot parse ' ' because "module.stripTypeScriptTypes" is…
- Cannot parse ' ' because "module.stripTypeScriptTypes" is…
- Cannot parse the module format of
- Custom CoverageProviderModule loaded from
- ${error instanceof Error ? error.message : String(error)}
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/c814e7fa17d9c3ac.
Report an issue: GitHub.
Appendix: 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 1fa9837ec2)