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

Improve CommonJS support #43

Merged
merged 1 commit into from
Dec 13, 2023
Merged

Improve CommonJS support #43

merged 1 commit into from
Dec 13, 2023

Conversation

etal2
Copy link
Contributor

@etal2 etal2 commented Dec 13, 2023

Currently importing the library in a CommonJS Typescript project with the following tsconfig settings:

"compilerOptions": {
    "module": "Node16",
    "moduleResolution": "Node16",
}

fails with this message:

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("csrf-csrf")' call instead.

The solution is to have a separate CommonJS types definition file with a .cts extension.

@psibean
Copy link
Contributor

psibean commented Dec 13, 2023

Interesting, nice catch!

I wasn't aware of the *.d.cts option until now - I rarely work with CommonJS nowadays, so this wouldn't really have been tested. Especially in terms of TypeScript, every TypeScript I touch is ESM, and then only in some cases, the output may be CommonJS.

@psibean psibean merged commit 6cecbd4 into Psifi-Solutions:main Dec 13, 2023
4 checks passed
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.

2 participants