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

client-lex-runtime-service build fails with error TS2403 when esModuleInterop is enabled #1515

Closed
trivikr opened this issue Sep 10, 2020 · 8 comments

Comments

@trivikr
Copy link
Member

trivikr commented Sep 10, 2020

Describe the bug
clients/client-lex-runtime-service build fails with error TS2403 when esModuleInterop is enabled.
Refs: #1512 (comment)

SDK version number
master

To Reproduce (observed behavior)

  • set esModuleInterop: true in tsconfig.json for client-lex-runtime-service
  • Run yarn build

build fails with TS2403 error:

Details
yarn run v1.22.5
$ yarn build:cjs && yarn build:es
$ tsc -p tsconfig.json
../../node_modules/@types/jest/index.d.ts:35:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'beforeEach' must be of type 'HookFunction', but here has type 'Lifecycle'.

35 declare var beforeEach: jest.Lifecycle;
               ~~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2734:13
    2734 declare var beforeEach: Mocha.HookFunction;
                     ~~~~~~~~~~
    'beforeEach' was also declared here.

../../node_modules/@types/jest/index.d.ts:37:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'afterEach' must be of type 'HookFunction', but here has type 'Lifecycle'.

37 declare var afterEach: jest.Lifecycle;
               ~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2752:13
    2752 declare var afterEach: Mocha.HookFunction;
                     ~~~~~~~~~
    'afterEach' was also declared here.

../../node_modules/@types/jest/index.d.ts:38:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'describe' must be of type 'SuiteFunction', but here has type 'Describe'.

38 declare var describe: jest.Describe;
               ~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2768:13
    2768 declare var describe: Mocha.SuiteFunction;
                     ~~~~~~~~
    'describe' was also declared here.

../../node_modules/@types/jest/index.d.ts:40:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xdescribe' must be of type 'PendingSuiteFunction', but here has type 'Describe'.

40 declare var xdescribe: jest.Describe;
               ~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:2789:13
    2789 declare var xdescribe: Mocha.PendingSuiteFunction;
                     ~~~~~~~~~
    'xdescribe' was also declared here.

../../node_modules/@types/jest/index.d.ts:41:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'it' must be of type 'TestFunction', but here has type 'It'.

41 declare var it: jest.It;
               ~~

  node_modules/@types/mocha/index.d.ts:2803:13
    2803 declare var it: Mocha.TestFunction;
                     ~~
    'it' was also declared here.

../../node_modules/@types/jest/index.d.ts:43:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xit' must be of type 'PendingTestFunction', but here has type 'It'.

43 declare var xit: jest.It;
               ~~~

  node_modules/@types/mocha/index.d.ts:2824:13
    2824 declare var xit: Mocha.PendingTestFunction;
                     ~~~
    'xit' was also declared here.

../../node_modules/@types/jest/index.d.ts:44:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'test' must be of type 'TestFunction', but here has type 'It'.

44 declare var test: jest.It;
               ~~~~

  node_modules/@types/mocha/index.d.ts:2817:13
    2817 declare var test: Mocha.TestFunction;
                     ~~~~
    'test' was also declared here.


Found 7 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior
build succeeds

Additional context
This issue is blocking enabling esModuleInterop for clients in #1512

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

The same issue with Cypress has been discussed in detail in cypress-io/cypress#6690 (comment)

It was fixed in cypress@4.6.0 by including types in a way to avoid clashing with jest types.
PR: cypress-io/cypress#7352

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

This SO answer suggests using skipLibCheck https://stackoverflow.com/a/57600242
It fixes the problem, but TypeScript will not be able to detect some errors if it's enabled https://stackoverflow.com/q/52311779

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

Bug report in jest repo wrt types conflict for expect jestjs/jest#8570
It was fixed and released in Jest 24.9.0 jestjs/jest#8571 (comment)

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

Another option is to set compilerOptions.types to ["mocha"] while compiling test files
SO answer: https://stackoverflow.com/a/57174947

But this list will need to be maintained in future when new types might be added which are required for testing. Documentation: https://www.typescriptlang.org/tsconfig#types

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

The issue is reproducible even after upgrading to latest dependencies of @types/mocha and @types/jest.

    "@types/jest": "^26.0.13",
    "@types/mocha": "^8.0.3",

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

Comment on jest repo explaining why @types/jest and @types/mocha are not going to work together because of conflicts.
jestjs/jest#9209 (comment)

@trivikr
Copy link
Member Author

trivikr commented Sep 10, 2020

This was an issue with PR #1512, as overwriting of tsconfig.json was enabled temporarily to add esModuleInterop: true which removed already set compilerOptions.types

It was fixed by manually adding setting esModuleInterop: true in tsconfig.json of clients.
As a follow-up, we'll plan to remove jest altogether from clients, as we're using mocha for integration testing

@trivikr trivikr closed this as completed Sep 10, 2020
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant