sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

TypeScript - Fix import for dependencies with no default export #73

Closed callmehiphop closed 5 years ago

callmehiphop commented 5 years ago

Started seeing this error popup

node_modules/p-queue/dist/index.d.ts:1:8 - error TS1259: Module '"/node_modules/eventemitter3/index"' can only be default-imported using the 'esModuleInterop' flag

1 import EventEmitter from 'eventemitter3';
         ~~~~~~~~~~~~

  node_modules/eventemitter3/index.d.ts:64:1
    64 export = EventEmitter;
       ~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
fregante commented 5 years ago

Has this bug been reported to TypeScript? TypeScript should not generate import default in the .d.ts file.

callmehiphop commented 5 years ago

@bfred-it Is this a TypeScript bug though? I assumed if my project had esModuleInterop set to false, it would apply that same configuration to my dependencies as well.

fregante commented 5 years ago

The bug is: generating a .d.ts file that doesn’t work with all TS configurations.

import default from ‘cjs’ only works in the current project because there’s a setting that enables it, but it should be a “temporary illusion” just for us, it shouldn’t then cause trouble to the users of this module.

It would be different if TS just supported esModuleInterop out of the box for everyone, without giving an option.