question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tsc type definition conflicts, duplicate identifiers in @types/mocha chai etc

See original GitHub issue

Project is https://github.com/ericblade/quagga2

Project has it’s own dependency on @types/mocha @types/chai declared. This is so editor support for typescript works correctly.

Running tsc on the project in the build step fails with duplicate definitions.

On top of that, since this is also causing typescript compilation to fail, when I run ‘cypress run’, which uses webpack-preprocessor to package, cypress just hangs indefinitely, when I would expect it to fail.

Running cypress open does not fail, as for speed reasons, I have configured open to not use webpack-preprocessor.

Reverting to 4.5.0 corrects the issues, and all tests run as normal.

Version of webpack-preprocessor doesn’t seem relevant – I tried both 5.2.1 which is what I used prior to the 4.6.0 upgrade, and 5.4.1, which was the recommended upgrade with cypress 4.6.0.

> @ericblade/quagga2@1.0.5 check-types D:\src\quaggajs
> tsc

node_modules/@types/chai/index.d.ts:19:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Message, ObjectProperty, ChaiPlugin, AssertionArgs, Operator, OperatorComparable, AssertionError, chai

19 declare namespace Chai {
   ~~~~~~~

  node_modules/cypress/types/chai/index.d.ts:19:1
    19 declare namespace Chai {
       ~~~~~~~
    Conflicts are in this file.

node_modules/@types/mocha/index.d.ts:17:15 - error TS2300: Duplicate identifier 'Mocha'.

17 declare class Mocha {
                 ~~~~~

  node_modules/cypress/types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/cypress/types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/cypress/types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/@types/mocha/index.d.ts:242:19 - error TS2300: Duplicate identifier 'Mocha'.      

242 declare namespace Mocha {
                      ~~~~~

  node_modules/cypress/types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/cypress/types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/cypress/types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/@types/mocha/index.d.ts:2814:15 - error TS2451: Cannot redeclare block-scoped variable 'mocha'.

2814 declare const mocha: BrowserMocha;
                   ~~~~~

  node_modules/cypress/types/mocha/index.d.ts:2814:15
    2814 declare const mocha: BrowserMocha;
                       ~~~~~
    'mocha' was also declared here.

node_modules/@types/mocha/index.d.ts:2848:6 - error TS2300: Duplicate identifier 'MochaDone'.  

2848 type MochaDone = Mocha.Done;
          ~~~~~~~~~

  node_modules/cypress/types/mocha/index.d.ts:2848:6
    2848 type MochaDone = Mocha.Done;
              ~~~~~~~~~
    'MochaDone' was also declared here.

node_modules/@types/mocha/index.d.ts:2851:6 - error TS2300: Duplicate identifier 'ReporterConstructor'.

2851 type ReporterConstructor = Mocha.ReporterConstructor;
          ~~~~~~~~~~~~~~~~~~~

  node_modules/cypress/types/mocha/index.d.ts:2851:6
    2851 type ReporterConstructor = Mocha.ReporterConstructor;
              ~~~~~~~~~~~~~~~~~~~
    'ReporterConstructor' was also declared here.

node_modules/@types/mocha/index.d.ts:2856:14 - error TS2300: Duplicate identifier 'Mocha'.     

2856     export = Mocha;
                  ~~~~~

  node_modules/cypress/types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/cypress/types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/cypress/types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/@types/mocha/index.d.ts:2860:14 - error TS2300: Duplicate identifier 'milliseconds'.

2860     export = milliseconds;
                  ~~~~~~~~~~~~

  node_modules/cypress/types/mocha/index.d.ts:2860:14
    2860     export = milliseconds;
                      ~~~~~~~~~~~~
    'milliseconds' was also declared here.

node_modules/@types/mocha/index.d.ts:2879:14 - error TS2300: Duplicate identifier 'common'.    

2879     export = common;
                  ~~~~~~

  node_modules/cypress/types/mocha/index.d.ts:2879:14
    2879     export = common;
                      ~~~~~~
    'common' was also declared here.

node_modules/cypress/types/chai/index.d.ts:19:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Message, ObjectProperty, ChaiPlugin, AssertionArgs, Operator, OperatorComparable, AssertionError, chai

19 declare namespace Chai {
   ~~~~~~~

  node_modules/@types/chai/index.d.ts:19:1
    19 declare namespace Chai {
       ~~~~~~~
    Conflicts are in this file.

node_modules/cypress/types/mocha/index.d.ts:17:15 - error TS2300: Duplicate identifier 'Mocha'.
17 declare class Mocha {
                 ~~~~~

  node_modules/@types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/@types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/@types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/cypress/types/mocha/index.d.ts:242:19 - error TS2300: Duplicate identifier 'Mocha'.

242 declare namespace Mocha {
                      ~~~~~

  node_modules/@types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/@types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/@types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/cypress/types/mocha/index.d.ts:2814:15 - error TS2451: Cannot redeclare block-scoped variable 'mocha'.

2814 declare const mocha: BrowserMocha;
                   ~~~~~

  node_modules/@types/mocha/index.d.ts:2814:15
    2814 declare const mocha: BrowserMocha;
                       ~~~~~
    'mocha' was also declared here.

node_modules/cypress/types/mocha/index.d.ts:2848:6 - error TS2300: Duplicate identifier 'MochaDone'.

2848 type MochaDone = Mocha.Done;
          ~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2848:6
    2848 type MochaDone = Mocha.Done;
              ~~~~~~~~~
    'MochaDone' was also declared here.

node_modules/cypress/types/mocha/index.d.ts:2851:6 - error TS2300: Duplicate identifier 'ReporterConstructor'.

2851 type ReporterConstructor = Mocha.ReporterConstructor;
          ~~~~~~~~~~~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2851:6
    2851 type ReporterConstructor = Mocha.ReporterConstructor;
              ~~~~~~~~~~~~~~~~~~~
    'ReporterConstructor' was also declared here.

node_modules/cypress/types/mocha/index.d.ts:2856:14 - error TS2300: Duplicate identifier 'Mocha'.

2856     export = Mocha;
                  ~~~~~

  node_modules/@types/mocha/index.d.ts:17:15
    17 declare class Mocha {
                     ~~~~~
    'Mocha' was also declared here.
  node_modules/@types/mocha/index.d.ts:242:19
    242 declare namespace Mocha {
                          ~~~~~
    and here.
  node_modules/@types/mocha/index.d.ts:2856:14
    2856     export = Mocha;
                      ~~~~~
    and here.

node_modules/cypress/types/mocha/index.d.ts:2860:14 - error TS2300: Duplicate identifier 'milliseconds'.

2860     export = milliseconds;
                  ~~~~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2860:14
    2860     export = milliseconds;
                      ~~~~~~~~~~~~
    'milliseconds' was also declared here.

node_modules/cypress/types/mocha/index.d.ts:2879:14 - error TS2300: Duplicate identifier 'common'.

2879     export = common;
                  ~~~~~~

  node_modules/@types/mocha/index.d.ts:2879:14
    2879     export = common;
                      ~~~~~~
    'common' was also declared here.


Found 18 errors.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:24 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ericbladecommented, Jun 9, 2020
1reaction
hallettjcommented, Apr 19, 2021

My workaround for chai-subset is to uninstall @types/chai-subset (which depends on @types/chai), and to instead place a modified version of the chai-subset type definitions in my project. I put this file in cypress/types/chai-subset.d.ts:

/**
 * This is copied from `@types/chai-subset`. The types package imports
 * `@types/chai` which conflicts with Cypress' definitions for chai which is why
 * this code is copied instead of installing that package.
 */

declare module "chai-subset" {
  global {
    namespace Chai {
      interface Assertion {
        containSubset(expected: any): Assertion
      }
      interface Assert {
        containSubset(val: any, exp: any, msg?: string): void
      }
    }
  }

  const chaiSubset: Chai.ChaiPlugin
  export = chaiSubset
}

I’m not sure it’s really necessary for @types/chai-subset to depend on @types/chai. If it didn’t have that dependency, and did not include this line then I think that would solve the problem for me.

/// <reference types="chai" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript 2 definitions for mocha, jasmine cause duplicate ...
Found it. Use the types option in tsconfig.json along with tsc version 2.x { "compilerOptions": { "target": "es5", "module": "commonjs", ...
Read more >
Error Ts2300: Duplicate Identifier 'Export=' - ADocLib
Running tsc on the project in the build step fails with duplicate definitions. Running cypress open does not fail as for speed reasons...
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, if ...
Read more >
Jasmine collision with Mocha (backend), Duplicate identifier ...
But when I do tsc in the be (the functions dir) I get node_modules/@types/mocha/index.d.ts:2649:13 - error TS2300: Duplicate identifier ...
Read more >
Firebase JavaScript SDK Release Notes - Google
Updated firebase/[product] entry point bundles to conform to Node.js ES module ... Added the missing type definitions for startAfter() and endBefore() .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found