The import statement consumes functionality exposed by an ECMAScript module. It can bring in one default export, selected named exports, or a complete module namespace, supporting reusable code and separation of concerns. section 1.4 section 6.4.3
Choose an import form according to the shape of the module API:
- Import one default export: import Block from './Block.js'; section 6.4.3
- Import selected named exports: import { checkIndex, checkLinkage } from './block/validations.js'; section 6.4.3
- Rename an imported binding with as, or gather named exports into a namespace with import * as ValidationsUtil. section 6.4.3
- Load conditionally with await import(path), trading static dependency declarations for dynamic module selection. section 6.4.3
Path and binding rules
ESM relative paths begin with ./ or ../, and file extensions must be explicit when present: import Transaction from './Transaction.js';. Imported bindings remain connected to their exports as live bindings, so named imports are not destructuring copies. section 6.4.1 section 6.4.3
Listing 6.11 Path specifiers using ESM
import Transaction from './Transaction.js';
import Transaction from '../Transaction.js';
import { curry } from '/lib/fp/combinators.js';
import { curry } from 'https://my.example.com/lib/fp/combinators.js'; #1
Compare relative, absolute, and remote ESM path specifiers in a compact listing. section 6.4.1












