module resolution
How a runtime or tool turns the name in an import, such as ./util.js or express, into the exact file to load.
In more detail
The name is called a specifier: relative ones start with ./ or ../, while bare ones are looked up in installed packages. Build tools and type checkers must follow the same rules as the runtime, or they will disagree about which file is meant.
Example
Node.js looks bare specifiers up in node_modules, treats node: ones as built in, and requires full file extensions in ES modules.Related terms
- module — A file of code whose functions, classes and variables other files can use by importing it.
- ECMAScript modules — The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
- module customization hooks — Functions you register with module.register() or module.registerHooks() to change how Node.js finds and loads modules.
- NodeNext — A module and moduleResolution setting that makes TypeScript follow exactly the module rules of current Node.js.
- module (compiler option) — The compiler option that says which module system the output uses and, with NodeNext, how each file is treated.
- package.json exports — The package.json fields that declare which files a package makes importable (exports) and which private shortcuts start with # (imports).
- CommonJS — Node.js's original module system, which loads code with require() and exports it with module.exports.
Taught in
- Native Module Systems: ESM Loader Hooks vs CommonJS — Node.js Internals & Backend Services
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript