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 resolution fails when trying to import the package from a CJS module #28

Open
tao-cumplido opened this issue Nov 13, 2024 · 0 comments · May be fixed by #29
Open

TypeScript resolution fails when trying to import the package from a CJS module #28

tao-cumplido opened this issue Nov 13, 2024 · 0 comments · May be fixed by #29

Comments

@tao-cumplido
Copy link

Are The Types Wrong lists the issue "Masquerading as ESM" for the regex package.

I guess the issue lies in package exports field, it only lists a single type definition file but an .mjs and a .cjs source for ESM and CJS respectively. Newer TS versions would need two definitions .d.mts and .d.cts. I believe they can generally be identical. There's some edge case import/export syntax only available in .cts files:
https://www.typescriptlang.org/docs/handbook/modules/reference.html#export--and-import--require

I haven't tested it, but I believe rewriting the exports field to something like this could work:

{
  "exports": {
    ".": {
      "import": {
        "types": "./dist/regex.d.mts",
        "default": "./dist/regex.mjs"
      },
      "require": {
        "types": "./dist/regex.d.cts",
        "default": "./dist/regex.cjs"
      }
    }
  }
}
@tao-cumplido tao-cumplido linked a pull request Nov 14, 2024 that will close this issue
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 a pull request may close this issue.

1 participant