Need one object that represents a module’s exports? In ESM, `import * as characters` creates a namespace object whose properties are the export names; a default export appears under `default`. Unlike a typical mutable object, the namespace is sealed and its properties are read-only. section 13.1.1
Listing 13.6 Importing a module as a namespace
import * as characters from "./4-default-export.ts"; #A console.assert( characters.default === "Ranma", "The default export is Ranma", ); console.assert( Object.keys(characters).length === 3, "All 3 exports are included in the namespace", );
This import gathers the default and named character exports under one namespace. section 13.1.1
A namespace import is useful when you need to inspect exports without naming each one in advance. When you only need selected exports, import those directly: bundlers can then omit unused code during tree-shaking. section 13.1.1
CommonJS interoperability
In Node.js, requiring an ESM module returns its namespace object. Access the default export as `.default`; it is not the whole object. This differs from importing a CommonJS module into ESM, where the whole CommonJS exports object is treated as the default import. section 13.2.1 section 13.1.1
