Skip to content

Instantly share code, notes, and snippets.

@zipang
Created October 9, 2019 11:47
Show Gist options
  • Save zipang/32d9ac8d141ddfe5881d93ef8da3d424 to your computer and use it in GitHub Desktop.
Save zipang/32d9ac8d141ddfe5881d93ef8da3d424 to your computer and use it in GitHub Desktop.
How to import es6 modules from inside a commn js executable node application
#!/usr/bin/env node
/**
* babel-register is all that is needed to require es6 module transparently
*/
require("babel-register")({
presets: ["env"]
});
const { someNamedExport } = require("./es6-module");
const someDefaultExport = require("./es6-module.js").default; // Notice how we must access the `default` property to access the default export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment