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

error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls #756

Open
dilame opened this issue Dec 19, 2023 · 3 comments · May be fixed by #757
Open

error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls #756

dilame opened this issue Dec 19, 2023 · 3 comments · May be fixed by #757
Labels
bug Something isn't working

Comments

@dilame
Copy link

dilame commented Dec 19, 2023

Version

5.26.2

Describe the bug

I just made initial setup of typesafe-i18n, trying to build my project now and stumbled into 3 TS errors

node_modules/typesafe-i18n/runtime/esm/runtime/src/index.d.ts:1:15 - 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("../../../../types/runtime/src/index.mjs")' call instead.

1 export * from '../../../../types/runtime/src/index.mjs'
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/typesafe-i18n/detectors/index.d.ts:1:15 - 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("../types/detectors/src/index.mjs")' call instead.

1 export * from '../types/detectors/src/index.mjs'
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/typesafe-i18n/utils/index.d.ts:1:15 - 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("../types/utils/src/index.mjs")' call instead.

1 export * from '../types/utils/src/index.mjs'

Reproduction

{
  "extends": "./tsconfig.checks.json",
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "target": "ESNext",
    "lib": ["ESNext", "DOM"],
    "types": ["node", "jest"],
    "removeComments": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false,
    "sourceMap": true,
    "resolveJsonModule": true,
    "baseUrl": "./",
  }
}

Logs

No response

Config

No response

Additional information

No response

@dilame dilame added the bug Something isn't working label Dec 19, 2023
@dilame
Copy link
Author

dilame commented Dec 19, 2023

I figured out the reason. Typescript reasonably consider node_modules/typesafe-i18n/utils/index.d.ts as CommonJS module because there is no type: "module" in `package.json.

@dilame dilame linked a pull request Dec 19, 2023 that will close this issue
@dilame
Copy link
Author

dilame commented Dec 19, 2023

To be honest, i'm surprised no one has reported about it yet. This issue should affect everyone with ESM + TypeScript setup

@chriscoomber
Copy link
Contributor

I'm not 100% sure if this is your exact issue, but if you are using metro, you might need to add cjs support in your metro.config.js: https://github.com/ivanhofer/typesafe-i18n/blob/main/packages/adapter-react/examples/expo/metro.config.js#L11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants