Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esModuleInterop flag required to build TypeScript project referencing v5.11.0 #1727

Closed
ejizba opened this issue Oct 24, 2022 · 3 comments · Fixed by #1769
Closed

esModuleInterop flag required to build TypeScript project referencing v5.11.0 #1727

ejizba opened this issue Oct 24, 2022 · 3 comments · Fixed by #1769
Labels
bug Something isn't working

Comments

@ejizba
Copy link

ejizba commented Oct 24, 2022

Bug Description

Starting in v5.11.0, it seems like the "esModuleInterop" flag is required to get a TypeScript build passing for a project referencing undici. It worked just fine in 5.10.0, and I believe the change to the types files occurred in the following PR by @arontsang, but I'm not sure if it was intentional: #1338

Reproducible By

  1. Clone this simple app: https://github.com/ejizba/undicibug
  2. Run npm install
  3. Run npm build

Expected Behavior

The build passes

Actual Behavior

The build fails with these errors:

node_modules/undici/types/client.d.ts:5:8 - error TS1259: Module '"/undiciBug/node_modules/undici/types/connector"' can only be default-imported using the 'esModuleInterop' flag

5 import buildConnector, {connector} from "./connector";
         ~~~~~~~~~~~~~~

  node_modules/undici/types/connector.d.ts:4:1
    4 export = buildConnector
      ~~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/undici/types/dispatcher.d.ts:6:13 - error TS1259: Module '"/undiciBug/node_modules/undici/types/readable"' can only be default-imported using the 'esModuleInterop' flag

6 import type BodyReadable from './readable'
              ~~~~~~~~~~~~

  node_modules/undici/types/readable.d.ts:4:1
    4 export = BodyReadable
      ~~~~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/undici/types/handlers.d.ts:1:8 - error TS1259: Module '"/undiciBug/node_modules/undici/types/dispatcher"' can only be default-imported using the 'esModuleInterop' flag

1 import Dispatcher from "./dispatcher";
         ~~~~~~~~~~

  node_modules/undici/types/dispatcher.d.ts:12:1
    12 export = Dispatcher;
       ~~~~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

Environment

Mac
Node 18

Additional context

I can work around the bug by setting esModuleInterop to true in the sample app linked above, but unfortunately that flag causes other problems in my "real" app 😮‍💨

@mcollina
Copy link
Member

@kibertoad could you take a look?

@kibertoad
Copy link
Contributor

Sure!

@kibertoad
Copy link
Contributor

Sorry for the delay, will finally have time to look at it on this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants