Language concepts
import()
Requests module loading when the expression executes. The returned promise fulfills with a namespace or rejects if loading, linking or evaluation fails. Multi-file example: save each listed file separately, then run the entry file with Node.js. See the packaged fixture for the original files.
Formal Syntax & Structure
javascript syntaxjavascript
import(specifier)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| specifier | string-coercible value | Module specifier interpreted by the host. |
Return Value
Promise
Fulfills with a module namespace object.
Working Example
Example Snippetjavascript
// File: feature.mjsexport default "ready";
// File: main.mjstry { const ns = await import("./feature.mjs"); console.log(ns.default); await import("./absent.mjs");} catch { console.log("load failed"); }