Created
October 9, 2019 11:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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