Skip to content

ts-loader inconsistent with ts compiler #1629

Open

Description

@danielvanmil

In my project I get some errors with the TS compiler (see code below)
The strange thing is I don't see/get the errors with Webpack/ts-loader.
All other errors are noticed correctly.

Any solution for this?

PS C:\danielm\git\gx\gitlab-projects\engatta\main\engatta-web> yarn tsc 
../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-react-npm-18.2.14-4d72cc1c1d-8c0.zip/node_modules/@types/react/ts5.0/global.d.ts:158:11 - error TS2451: Cannot redeclare block-scoped variable 'TrustedHTML'.

158 interface TrustedHTML { }
              ~~~~~~~~~~~

  ../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-trusted-types-npm-2.0.2-035cb17c5e-8c0.zip/node_modules/@types/trusted-types/index.d.ts:14:11
    14     const TrustedHTML: typeof lib.TrustedHTML;
                 ~~~~~~~~~~~
    'TrustedHTML' was also declared here.
  ../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-trusted-types-npm-2.0.2-035cb17c5e-8c0.zip/node_modules/@types/trusted-types/index.d.ts:15:10
    15     type TrustedHTML = lib.TrustedHTML;
                ~~~~~~~~~~~
    and here.

../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-trusted-types-npm-2.0.2-035cb17c5e-8c0.zip/node_modules/@types/trusted-types/index.d.ts:14:11 - error TS2451: Cannot redeclare block-scoped variable 'TrustedHTML'.

14     const TrustedHTML: typeof lib.TrustedHTML;
             ~~~~~~~~~~~

  ../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-react-npm-18.2.14-4d72cc1c1d-8c0.zip/node_modules/@types/react/ts5.0/global.d.ts:158:11
    158 interface TrustedHTML { }
                  ~~~~~~~~~~~
    'TrustedHTML' was also declared here.

../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-trusted-types-npm-2.0.2-035cb17c5e-8c0.zip/node_modules/@types/trusted-types/index.d.ts:15:10 - error TS2451: Cannot redeclare block-scoped variable 'TrustedHTML'.

15     type TrustedHTML = lib.TrustedHTML;
            ~~~~~~~~~~~

  ../../../../../../../Users/danielm/AppData/Local/Yarn/Berry/cache/@types-react-npm-18.2.14-4d72cc1c1d-8c0.zip/node_modules/@types/react/ts5.0/global.d.ts:158:11
    158 interface TrustedHTML { }
                  ~~~~~~~~~~~
    'TrustedHTML' was also declared here.


Found 3 errors.

Expected Behaviour

All errors logged/visible

Actual Behaviour

Some (TS2451) errors are ignored or maybe not fatal?

Steps to Reproduce the Problem

Location of a Minimal Repository that Demonstrates the Issue.

Activity

  1. changed the title [-]ts-loader inconsistent with ts compiler with errors[/-] [+]ts-loader inconsistent with ts compiler[/+] on Sep 13, 2023
  2. longhotsummer commented on Jul 1, 2024

    @longhotsummer

    You can work around this by setting skipLibCheck: true in your tsconfig. See https://stackoverflow.com/questions/41478596/error-ts2451-cannot-redeclare-block-scoped-variable

  3. Marcono1234 commented on Apr 20, 2026

    @Marcono1234

    Not sure if this was the original issue here, but also make sure ts-loader picks the 'right' typescript dependency. In your webpack config you can use the following, which will then print something like "ts-loader: Using typescript@6.0.2 and .../tsconfig.json" to console.

    use: {
      loader: 'ts-loader',
      options: {
        // Print used TypeScript version for easier troubleshooting
        logLevel: 'info',
      },
    },

    In my case I had an npm workspace project where the subpackages used webpack and ts-loader, and had a typescript 6.0 dependency, but the root package used an outdated typescript-eslint dev dependency which required typescript < 6.0. That apparently led ts-loader to use a typescript 5.9 dependency required by typescript-eslint (due to this conflict package-lock.json apparently listed the 5.9 dependency as well as subpackage-specific 6.0 dependencies). Not sure who is at fault here (npm, ts-loader or myself in case the project setup is flawed).

    I have (hopefully) solved this now by updating the typescript-eslint dependency and adding an explicit typescript dependency to the root project as well (even though it does not actually need it); that should hopefully lead to a version conflict error in the future, instead of mismatching versions being used for the root package and the subpackages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions