Skip to content

Instantly share code, notes, and snippets.

@jbrantly
Created March 22, 2016 15:34
Show Gist options
  • Save jbrantly/29969e8448d40538832a to your computer and use it in GitHub Desktop.
Save jbrantly/29969e8448d40538832a to your computer and use it in GitHub Desktop.
The problem with the CJS-ES6 gap
// ES6 exports
export var foo = 1
export var bar = true
// CJS analog
module.exports = {
foo: 1,
bar: true
}
// Importing all exports from the above ES6 module
import * as mod from 'module'
// I think it can be argued that if you're allowing CJS to be imported using ES6 syntax, then
// the above CJS module could also be imported using:
import * as mod from 'module'
// However, if you allow the above, then it in turn also means you can do this:
// CJS module
module.exports = function foo() {}
// Importing...
import * as func from 'module'
@bmeck
Copy link

bmeck commented Mar 22, 2016

I heavily recommend people use import mydefault from 'foo' over * when doing interop with CJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment