Node 26 native TypeScript execution throws ERR_MODULE_NOT_FOUND on extensionless relative imports
ERR_MODULE_NOT_FOUNDCannot find module imported from .ts under native type strippingrewriteRelativeImportExtensionsObservation / Symptom
Executing a TypeScript entrypoint directly with Node 26 (node ./src/cli.ts) fails immediately on the first relative import that omits a file extension or uses a compiled .js specifier when only .ts source files exist on disk:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module './parser' imported from ./src/cli.ts
at finalizeResolution (node:internal/modules/esm/resolve:275:11)Root Cause / Reality Check
Node 26 runs native TypeScript type stripping by default, but its ESM resolver strictly follows standard Node ESM rules: it never probes for .ts extensions on extensionless specifiers and does not map .js imports back to .ts files on disk. Bundlers like Vite, esbuild, and Wrangler accept extensionless imports, creating a mismatch whenever scripts or test helpers are executed directly by node.
Working Fix / Actionable Outcome
- Write explicit
.tsextensions on relative imports in files executed directly by Node:
import { parseFrontmatter } from "./parser.ts";- Update
tsconfig.json(TypeScript 5.8+) so type-checking and optionaltscemit agree with native Node execution:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"erasableSyntaxOnly": true,
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
"verbatimModuleSyntax": true
}
}- Use
import type { ... }for type-only imports so erased types never leave dangling runtime bindings.
Dead Ends (What Didn't Work)
- Passing
--experimental-specifier-resolution=nodefails because the flag was removed in modern Node releases. - Setting
"moduleResolution": "Bundler"intsconfig.jsonsilences IDE errors but has zero effect on Node's runtime ESM resolver. - Adding
--experimental-strip-typesexplicitly does not change extension resolution behavior.
Verification
Validate syntax with Node 26 directly and verify strict TypeScript compilation:
node --check ./src/cli.ts
npx tsc --noEmitBoth commands exit 0 with no ERR_MODULE_NOT_FOUND or TS5097 diagnostics.