ES6 modules—formally, ECMAScript modules (ESM)—are JavaScript’s standard way to split code into reusable files. A module makes selected values available with export; another module uses import to access them. For example:
// math.js
export const pi = 3.14159;
export function area(r) {
return pi * r * r;
}
// app.js
import { pi, area as circleArea } from './math.js';
console.log(circleArea(2));
That syntax is shared by modern browsers and Node.js, but each host has its own rules for loading files and resolving module paths.
How do exports and imports work?
A module can export top-level declarations—such as functions, variables, or classes—and another module can import them. The export declaration defines the module’s public interface; code that is not exported remains private to that module.
MDN describes static imports as importing “read-only live bindings” from another module. The importer cannot assign a new value to an imported binding, but it can observe changes made to an exported binding by the module that owns it. MDN’s static import reference explains the syntax and behavior.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
What is the difference between named and default exports?
Choose an export style based on how you want consumers to see and use the module’s interface. Neither style is inherently better.
| Style | Export example | Import example | Useful when |
|---|---|---|---|
| Named | export function area(r) { ... } |
import { area } from './math.js'; |
The module exposes distinct, clearly named values. Importers can select specific exports or rename one with as. |
| Default | export default function format(value) { ... } |
import format from './formatter.js'; |
The module has one primary value that consumers should be able to import directly. |
A module can have named exports and one default export. Named imports must use the exported name unless aliased; a default import uses the local name chosen by the importer. To access a module’s named exports as properties on one object, use a namespace import such as import * as math from './math.js';.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
How do you load modules in a browser?
Use a module script as the browser entry point. Static import and export syntax is allowed in module scripts, not ordinary scripts:
<script type="module" src="./main.js"></script>
Browser module specifiers are URL-like. For a nearby file, write an explicit relative path such as ./math.js; including the extension is normally necessary. A bare name such as square is not automatically resolved to a package in a browser. It needs an import map that maps the name to a URL; otherwise, the browser throws a TypeError for the unresolved specifier. Browsers also support inline module scripts and import maps. See MDN’s JavaScript modules guide for those browser behaviors.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
How do you enable ES modules in Node.js?
Node.js recognizes a file as ESM through one of three mechanisms: the .mjs extension, a nearest package.json with the top-level field "type": "module", or the --input-type=module option for input supplied to Node. In a package marked with "type": "module", its .js files are treated as ES modules.
For example, a project can opt in through its package file:
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
{
"type": "module"
}
Then a .js file in that package can use static imports. If Node reports Cannot use import statement outside a module, check whether the file is being treated as CommonJS and mark it as ESM using one of the supported mechanisms. Node’s documentation calls ECMAScript modules “the official standard format to package JavaScript code for reuse.” See Node.js ECMAScript modules and Node.js package documentation for the loading rules.
When should you use static import or dynamic import()?
Use static imports for dependencies a module needs as part of its normal startup. Static imports are top-level declarations with fixed string-literal specifiers. The host can resolve and link those dependencies before evaluating the module body, which supports features such as top-level await. Their declarations are processed before the rest of the module body; this is sometimes called hoisting, but it is not ordinary function hoisting.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Use dynamic import() when code should be loaded conditionally or only when needed. It is an expression that returns a promise fulfilling with a module object:
button.addEventListener('click', async () => {
const { renderChart } = await import('./chart.js');
renderChart();
});
Dynamic imports are asynchronous and can defer loading until a user action or other condition. Browser support depends on context: import() is permitted on the main thread and in shared or dedicated workers, but it throws in service workers and worklets. Consult MDN’s dynamic import reference for its promise behavior and modules guide for browser-context details.
Why do module paths behave differently in browsers and Node.js?
ECMAScript defines module syntax, but it does not make browser and Node.js path resolution identical. Browsers resolve URL-like specifiers, so local imports commonly use explicit relative paths and extensions; bare names require an import map. Node applies its own file and package rules, including its ESM markers and package resolution behavior. A specifier that works in one host may not work in the other without adjustment.
Node also supports interoperability between ESM and CommonJS. In particular, a CommonJS module can load an ES module with dynamic import(); static import declarations belong in ES modules. For package and interoperability details, refer to Node.js ESM documentation.
Recommended Free Tools
What should you check when an import fails?
- Browser says it cannot use an import statement: Load the entry file with
<script type="module">, not a classic script. - A browser cannot resolve a bare name: Use an appropriate relative or absolute URL, or define an import map for the bare specifier.
- Node rejects static import: Confirm the file is ESM, using
.mjs, a nearest package’s"type": "module", or the appropriate input mode. - A path works in one environment but not another: Check the host’s resolution rules; browser URL resolution and Node package resolution are different.
- Static import is inside a function or condition: Move it to module top level, or use
import()for conditional loading. - Default and named imports do not match: Use braces for a named export, such as
import { area } from './math.js';, and no braces for a default export, such asimport format from './formatter.js';. - A circular dependency behaves unexpectedly: ESM supports cycles, but evaluation order can expose an imported binding before it has been initialized. Review initialization dependencies and test the cycle deliberately.
Which module approach fits your situation?
Compare the choices along four separate axes rather than treating them as alternatives in one category:
Quick Recap
- Export API: Named exports make available names explicit at the import site; a default export makes one primary value convenient to import.
- Loading time: Static imports declare startup dependencies; dynamic
import()allows conditional or on-demand loading. - Specifier resolution: Browsers use URL-like paths and import maps; Node follows its file and package rules.
- Interoperability: ESM uses static import declarations, while Node offers dynamic
import()for loading ESM from CommonJS.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

