An Update on ES6 Modules in Node.js
James M Snell
1K36

Is it not as simple as using ES6 syntax for importing ES6 modules and CommonJS syntax for CommonJS imports?

import {foo as Foo} from “./foo” is the mechanism for identifying an ES6 module.

var Foo = require(“./foo”) is the mechanism for identifying the CJS module.

Typescript has no problems with this. The commonjs output looks like this:

var mod1_1 = require("./mod1");

exports.mod1 = mod1;

Whereas the ES6 output looks like this:

import { mod1 } from “./mod1”;

export { mod1 }

Show your support

Clapping shows how much you appreciated Corey Alix’s story.