TypeStrong / ts-loader

TypeScript loader for webpack
https://johnnyreilly.com/ts-loader-goes-webpack-5
MIT License
3.45k stars 428 forks source link

Updating to ts-loader@9.4.4 results in TS2502: 'AbortController' is referenced directly or indirectly in its own type annotation when used with @types/node@20.5.1 #1625

Closed tristanls closed 1 year ago

tristanls commented 1 year ago

Expected Behaviour

Expect build success.

Actual Behaviour

Error: [tsl] ERROR in node_modules/@types/node/globals.d.ts(70,13)
      TS2502: 'AbortController' is referenced directly or indirectly in its own type annotation.
    at makeError (node_modules/ts-loader/dist/utils.js:93:19)
    at node_modules/ts-loader/dist/utils.js:63:27
    at Array.map (<anonymous>)
    at formatErrors (node_modules/ts-loader/dist/utils.js:46:14)
    at provideErrorsToWebpack (node_modules/ts-loader/dist/after-compile.js:167:62)
    at node_modules/ts-loader/dist/after-compile.js:36:9
    at node_modules/ts-loader/dist/instances.js:206:13
    at fn (node_modules/webpack/lib/Compilation.js:479:10)
    at _next1 (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:48:1)
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:69:1)
ts-loader-default_e3b0c44298fc1c14
Error: [tsl] ERROR in node_modules/@types/node/globals.d.ts(77,13)
      TS2502: 'AbortSignal' is referenced directly or indirectly in its own type annotation.
    at makeError (node_modules/ts-loader/dist/utils.js:93:19)
    at node_modules/ts-loader/dist/utils.js:63:27
    at Array.map (<anonymous>)
    at formatErrors (node_modules/ts-loader/dist/utils.js:46:14)
    at provideErrorsToWebpack (node_modules/ts-loader/dist/after-compile.js:167:62)
    at node_modules/ts-loader/dist/after-compile.js:36:9
    at node_modules/ts-loader/dist/instances.js:206:13
    at fn (node_modules/webpack/lib/Compilation.js:479:10)
    at _next1 (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:48:1)
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:69:1)
ts-loader-default_e3b0c44298fc1c14

For reference, the relevant contents of @types/node/globals.d.ts referenced:

declare var AbortController: typeof globalThis extends {onmessage: any; AbortController: infer T}
    ? T
    : {
        prototype: AbortController;
        new(): AbortController;
    };

declare var AbortSignal: typeof globalThis extends {onmessage: any; AbortSignal: infer T}
    ? T
    : {
        prototype: AbortSignal;
        new(): AbortSignal;
        abort(reason?: any): AbortSignal;
        timeout(milliseconds: number): AbortSignal;
    };

Steps to Reproduce the Problem

Upgrade to ts-loader@9.4.4.

NOTE: Downgrading to ts-loader@9.4.3 results in successful build with no errors. NOTE: Using typescript@5.1.6

I don't have very clear reproduction steps. I observed this when doing bunch of dependency updates for a project. Was able to isolate everything to the difference between ts-loader@9.4.4 and ts-loader@9.4.3. Reporting here in hopes that perhaps folks familiar with ts-loader might know what happened by inspection.

Location of a Minimal Repository that Demonstrates the Issue.

N/A

tristanls commented 1 year ago

I'm guessing that this is due to my tsconfig.json having compilerOptions.skipLibCheck = false since setting it to true resolves the build issue.

Appears to be a problem with @types/node/global.d.ts surfaced by making skipLibCheck overridable.