coderef

JavaScript modulesBaseline · Widely available

JavaScript modules allow code to be organized into reusable units. Modules use import to load other modules and export to declare what is available to import from other modules. In HTML, modules are loaded with <script type="module">.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since May 9, 2018. Widely available since Nov 9, 2020.

Browser support

DesktopChrome
1–60Not supported
61+Supportedsince Sep 5, 2017
Current: 155
Edge
12–15Not supported
16+Supportedsince Oct 17, 2017
Current: 154
Firefox
1–59Not supported
60+Supportedsince May 9, 2018
Current: 157
Safari
1–10.1Not supported
11+Supportedsince Sep 19, 2017
Current: 27
MobileChrome Android
18–60Not supported
61+Supportedsince Sep 5, 2017
Current: 155
Firefox Android
4–59Not supported
60+Supportedsince May 9, 2018
Current: 157
Safari iOS
1–10.3Not supported
11+Supportedsince Sep 19, 2017
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: import.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.

Sub-features

Support for each part of the feature (15). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Worklet.ecmascript_modules8080114158011415
script.nomodule61166011616011
script.type.module61166010.1616010.3
import63796711.1636711.3
import_meta64796211.1646212
import_meta.resolve10510510616.410510616.4
export61166010.1616010.3
export.arbitrary_module_namespace_identifier_names88888714.1888714.5
export.default61166010.1616010.3
export.namespace72798014.1728014.5
import61166010.1616010.3
import.arbitrary_module_namespace_identifier_names88888714.1888714.5
import.import_attributes12312313817.212313817.2
import.worklet_support✕✕114✕✕114✕
script.type.module✕✕117✕✕117✕