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

fix: use namespace imports instead of default imports and remove the need to enable esModuleInterop in tsconfig #239

Closed

Conversation

jaapvanblaaderen
Copy link

Changes

Make the project suitable for usage in projects that have esModuleInterop disabled (or not set) in tsconfig.

  • use namespace imports instead of default imports
  • remove esModuleInterop setting in tsconfig

Background

I ran into some issues with the way sinon is imported after upgrading from aws-sdk-client-mock from 3.0.0 to 4.0.2. My project has esModuleInterop disabled which leads to the following error when running npx tsc:

src/mockClient.ts:2:8 - error TS1259: Module '"aws-sdk-client-mock2/node_modules/.pnpm/@[email protected]/node_modules/@types/sinon/index"' can only be default-imported using the 'esModuleInterop' flag

2 import sinon, {SinonSandbox, SinonStub} from 'sinon';
         ~~~~~

  ../../node_modules/.pnpm/@[email protected]/node_modules/@types/sinon/index.d.ts:1751:1
    1751 export = Sinon;
         ~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.


Found 1 error in src/mockClient.ts:2

…need to enable `esModuleInterop` in tsconfig
Ensures it plays nicely with the namespace import and ensure `pnpm test-types` succeeds
@jaapvanblaaderen
Copy link
Author

Closing this PR. I've read a bit more on esModuleInterop and the default settings for node projects. With "module": "NodeNext", esModuleInterop is set to true by default. I changed my project to use this so this fixes my issue as well.

@jaapvanblaaderen jaapvanblaaderen deleted the fix-imports branch September 26, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant