TypeScript

NodeNext and type-only imports

NodeNext models Node’s module resolution rules in TypeScript. File extensions and package scope determine the module format; type-only imports describe contracts without adding runtime imports. 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. 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. Evidence: Actual TypeScript source execution, independent tsc check. Source: https://www.typescriptlang.org/docs/handbook/modules/reference.html

Formal Syntax & Structure

nodejs syntaxnodejs
See example for the scoped contract

Working Example

Example Snippetnodejs
import type { Book } from './book.mts';import { label } from './book.mts';const book: Book = { id: 'b1', title: 'Rivers' };console.log(label(book));
Node.js Reference