JavaScript import Statement
The import declaration brings values exported by another JavaScript module into the current module. import() loads a module on demand.
Description
The import declaration reads bindings exported by another module. You can import the default export, named exports (optionally renamed with as), everything as a namespace object, or just run a module for its side effects. Imports are hoisted, read-only live bindings, and the module is loaded and run only once however many times it's imported.
Static import declarations only work in modules, which in a browser means a <script type="module"> or a file imported by one. The import() function-like expression loads a module dynamically and returns a promise, which is useful for loading code only when it's needed. Import maps let you use bare names like 'lodash' in the browser.
Module specifiers in the browser must be full or relative URLs, such as './utils.js' or '/js/app.js', unless an import map defines a bare name. Importing JSON or CSS needs an import attribute, for example import data from './data.json' with { type: 'json' }. Because modules are deferred by default and loaded only once, a module's top-level code runs a single time, however many other modules import it.
Syntax
import defaultExport from './module.js';
import { name1, name2 as alias } from './module.js';
import * as ns from './module.js';
import './module.js';
const mod = await import('./module.js');Example
Browser Support
The following information will show you the current browser support for the import statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





