Last active
May 6, 2024 09:04
-
-
Save brianleroux/6c649f3a2cfa4edea296 to your computer and use it in GitHub Desktop.
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
// Node style module writ in ES6 syntax: | |
exports default foo = () => console.log(‘hi’) | |
// Unfortunately “literally” transpiles to this: | |
exports.default = function foo() { | |
return console.log(‘hi’) | |
} | |
// Which means this will fail: | |
var foo = require(‘./foo’) | |
foo() // object is not a function! | |
// But this will work: | |
var foo = require(‘./foo’).default | |
foo() // outputs 'hi' | |
// There is a fix! | |
// | |
// If we compile with 6to5 we get what we expect! | |
module.exports = function foo() { | |
return console.log(‘hi’) | |
} | |
// call as usual | |
var foo = require(‘./foo’) | |
foo() // outputs 'hi'! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment