Node module resolution and types
Local baseline: Node.js 22.16.0. Actual TypeScript source execution, independent tsc check. TypeScript 5.8.3; no third-party packages.
Try the local example
export interface Book { id: string; title: string }export function label(book: Book): string {return `${book.id}: ${book.title}`;}import type { Book } from './book.mts';import { label } from './book.mts';const book: Book = { id: 'b1', title: 'Rivers' };console.log(label(book));Run node --experimental-strip-types main.mts in a disposable directory with the files shown. Expected standard output:
b1: RiversAn experimental warning is expected on stderr for this local version.
Check independently with tsc --strict --noEmit --target es2022 --module nodenext --allowImportingTsExtensions main.mts.
How it works
The fixture uses .mts files to select ESM explicitly. A .mjs specifier is appropriate in source intended to emit .mjs files: the compiler resolves it to the matching .mts source. The direct native execution lane instead uses actual .mts extensions. This fixture uses the latter with allowImportingTsExtensions and noEmit. For emitted projects use an explicit output strategy such as .mjs specifiers or verified extension rewriting. Pin TypeScript and compatible @types/node for projects using Node APIs; ambient declarations do not install runtime modules.
Common mistake
Do not use extensionless relative ESM imports just because a bundler accepts them. Also do not import a type as a runtime value in native stripping mode.
Practice
Add a second type to the module and import it with import type. Compare native execution and the compiler check.
Documentation: primary source. Candidate lookup: node-node-module-resolution-and-types-lookup. Prerequisite: node-typescript-compilation-and-type-stripping (platform route unverified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Node module resolution and types — knowledge check
Apply the lesson’s contracts and identify common boundary mistakes.
Which extension explicitly selects ESM TypeScript?
What does import type do?
Why use noEmit with this direct .mts import fixture?