Loading ES Modules in Node.js Projects
Loading ES Modules in Node.js Projects
Apr 10, 2024
·
1 min read
·
111
Words
·
-Views
-Comments
Node.js supports ES module import. You can load ES modules through import, but there are some conditions. If not met, it will still throw errors.

Note: import in Node.js differs from the browser side.
Import Local JS Modules
- Declare
type:modulein thepackage.jsonof the folder where the js file is located - File extension should be
mjs
Import URL
Executing import(url) in Node throws error ERR_UNSUPPORTED_ESM_URL_SCHEME
Error code explanation:
importwith URL schemes other thanfileanddatais unsupported.
From this, we can know that dynamic import in Node.js doesn’t support URLs. However, for example, Deno does support URLs, but Deno doesn’t consider CommonJS and doesn’t have this historical baggage.

