You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Library cannot be consumed from the CJS context when using TypeScript as of TS1479 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("i18next-fs-backend")' call instead. To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with `{ "type": "module" }`.
We should be able to import this library both from CJS context and ESM context.
Your Environment
runtime version: node v18
i18next version: ^22.4.9
os: Mac
Solution 🔥
In order to solve the issue you have to provide two different types declaration files, for CJS and for ESM.
I played around a bit with the package.json configuration and found out that this one is actually working, allowing me to consume this library, not matter the context (CJS / ESM).
Although "./cjs/index.d.ts" and "./esm/index.js" is the same file.
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.
🐛 Bug Report
Library cannot be consumed from the CJS context when using TypeScript as of TS1479 error:
To Reproduce
https://codesandbox.io/s/i18next-fs-backend-issue-s4qlzc?file=/src/index.ts
Expected behavior
We should be able to import this library both from CJS context and ESM context.
Your Environment
Solution 🔥
In order to solve the issue you have to provide two different types declaration files, for CJS and for ESM.
I played around a bit with the package.json configuration and found out that this one is actually working, allowing me to consume this library, not matter the context (CJS / ESM).
Although "./cjs/index.d.ts" and "./esm/index.js" is the same file.
Related topics 🔥
microsoft/TypeScript#49299
Swatinem/rollup-plugin-dts#210
The only one workaround for now
😢
The text was updated successfully, but these errors were encountered: