Skip to content

Instantly share code, notes, and snippets.

@FND
Created April 21, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FND/9442b13e4ca51fc511d9d01526aac681 to your computer and use it in GitHub Desktop.
Save FND/9442b13e4ca51fc511d9d01526aac681 to your computer and use it in GitHub Desktop.
static vs. dynamic ESM imports
$ mkdir -p node_modules/my-lib
$ cp package.json node_modules/my-lib/
$ mv my_lib.js node_modules/my-lib/index.js

$ node index_static.js
$ node index_dynamic.js
main();
async function main() {
let { name } = await import("my-lib");
console.log(`== ${name} ==`);
}
import { name } from "my-lib";
console.log(`== ${name} ==`);
export let name = "mylib";
{
"type": "module",
"main": "index.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment