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

Typescript error when using CommonJS module outputs #35

Closed
esuh-descript opened this issue Mar 22, 2024 · 2 comments
Closed

Typescript error when using CommonJS module outputs #35

esuh-descript opened this issue Mar 22, 2024 · 2 comments

Comments

@esuh-descript
Copy link
Contributor

I am running across this bug when trying to import this package into a Typescript project configured to emit CommonJS modules:

$ pnpm run typecheck
> temporal-polyfill-bug@1.0.0 typecheck /src/temporal-polyfill-bug
> tsc --build tsconfig.json

index.ts:1:26 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("temporal-polyfill")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/src/temporal-polyfill-bug/package.json'.

1 import { Temporal } from 'temporal-polyfill';
                           ~~~~~~~~~~~~~~~~~~~


Found 1 error.

 ELIFECYCLE  Command failed with exit code 1.

I've reproduced the above bug using a minimal example by cloning, running pnpm i, and then pnpm run typecheck.

I believe a fix is relatively straightforward based on microsoft/TypeScript#53045.

@arshaw
Copy link
Member

arshaw commented Mar 27, 2024

Thanks @esuh-descript , I'll make a .cts file for the next version.

@arshaw
Copy link
Member

arshaw commented Apr 6, 2024

This has been fixed in v0.2.4

@esuh-descript, I embedded your test case into the codebase's CI to ensure things don't break in the future. Thanks for that!

@arshaw arshaw closed this as completed Apr 6, 2024
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

No branches or pull requests

2 participants