-
-
Notifications
You must be signed in to change notification settings - Fork 627
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken types using node16+ moduleResolution strategy with ESM #2010
Comments
Is this really true? |
The cause is that the index.d.ts file has a corresponding index.js file alongside it, which is CJS. So that type definition is assumed to be CJS by TypeScript. The fix would be to have a type definition generated for both the ESM & CJS files, and use the "exports" entry in the package.json to point to the correct one depending on CJS/ESM, or just omitting them and allowing typescript to find a There are a few examples of how to fix this on their page for the issue, https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md#common-causes For this library, the likely simplest solution would be to have an |
Would you like to try a PR? |
I'm happy to give a PR a go, this issue also affects the other i18next libraries so I'll do this one first and follow with others |
The is no If you want to support ESM + CommonJS + TypeScript all configs, it would be a bit complex. Types for ESM and CommonJS must be separately like: {
"exports": {
".": {
"import": {
// a `package.json` with `type: "module"` is also required
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
}
} See also https:github.com/sheremet-va/dual-packaging#using-tsc |
See #2012 I've tested on my local machine It should both be working at the same time now. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
please try with v23.7.3 |
馃悰 Bug Report
Using TypeScript with
moduleResolution
set tonode16
ornodenext
,module
set to any ESM module (such asesnext
), and"type": "module"
within the package.json, TypeScript is unable to correctly determine types for i18next imports due to it inferring the provided index.d.ts file as CJS when the underlying import is ESM, due to the singleindex.d.ts
file being used for both ESM & CJS.This is further explained on this page, https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md
To Reproduce
Reproduction steps:
"moduleResolution": "node16", "module": "esnext"
, and a package.json containing"type": "module"
, the following code produces type errorsExpected behavior
There should be an index.d.ts file per entrypoint, so that it's correctly inferring CJS or ESM based on the types, and the types therefore work.
Your Environment
The text was updated successfully, but these errors were encountered: