I'm using TypeScript with an ES6 module & target configuration.
Trying to do the following (after installing eventemitter3 via npm and its definition via tsd):
import EventEmitter from 'eventemitter3'
fails with the message:
Module "eventemitter3" has no default export.
When trying to import via:
import * as EventEmitter from 'eventemitter3'
Then TypeScript's type checking is fine, but when I actually get as EventEmitter is an object, containing the properties 'prefixed' and 'default', which is of course not what I need (I want to get the EventEmitter function constructor which is inside the default property).
This seems like an issue with the definition itself.
How can I import eventemitter3 correctly with ES6 syntax?
Thanks!
Bar.
Are you using Babel? This might related to your problem: #8005
I think that once you're changing export = to export default in the definition file, you make it incompatible with CommonJS code, so definition file authors are reluctant to make this change (not sure though)...
Any progress of this? I had to do exactly what @Bartzy said, change it to export default. I wonder how to persue this if this breaks the modules for commonjs...
I'm currently running systemjs at it works fine with this change... Or is there a way to change the structure of the d.ts file to fix this?
You can use import * as EventEmitter from 'eventemitter3' for now. See #8005 as mentioned above by @JakubJagoda.
Most helpful comment
I think that once you're changing
export =toexport defaultin the definition file, you make it incompatible with CommonJS code, so definition file authors are reluctant to make this change (not sure though)...