module.exports vs. export default en Node.js y ES6
¿Cuál es la diferencia entre Node'smodule.exports
y ES6export default
? Estoy tratando de averiguar por qué me sale el error "__ no es un constructor" cuando intentoexport default
en Node.js 6.2.2.
'use strict'
class SlimShady {
constructor(options) {
this._options = options
}
sayName() {
return 'My name is Slim Shady.'
}
}
// This works
module.exports = SlimShady
Quéno lo hace trabajo'use strict'
class SlimShady {
constructor(options) {
this._options = options
}
sayName() {
return 'My name is Slim Shady.'
}
}
// This will cause the "SlimShady is not a constructor" error
// if in another file I try `let marshall = new SlimShady()`
export default SlimShady