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

Types are not correctly exported for a package supporting both ESM and CJS #176

Open
duniul opened this issue Sep 19, 2023 · 5 comments · May be fixed by #177
Open

Types are not correctly exported for a package supporting both ESM and CJS #176

duniul opened this issue Sep 19, 2023 · 5 comments · May be fixed by #177

Comments

@duniul
Copy link

duniul commented Sep 19, 2023

Context

The typings.d.ts are currently only exposed via the types field in package.json, which results in the following error in TypeScript:

error TS7016: Could not find a declaration file for module 'better-ajv-errors'. './node_modules/better-ajv-errors/lib/esm/index.mjs' implicitly has an 'any' type.
  There are types at '/Users/daniel/Projects/toca/toca-ts-packages/packages/confy/node_modules/better-ajv-errors/typings.d.ts', but this result could not be resolved when respecting package.json "exports". The 'better-ajv-errors' library may need to update its package.json or typings.

Potential fix

Follow the guidelines listed here: https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing

Basically, you would need to add a types field to each exports entry in package.json, both pointing to unique files.

Edit:
PR with fix: #177

@torifat
Copy link
Collaborator

torifat commented Sep 19, 2023

Thanks for reporting this. I will try to fix it soon.

However, did you try using a different moduleResolution option? See https://publint.dev/better-ajv-errors@1.2.0

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

duniul commented Sep 19, 2023

@torifat I did, but thought I'd report it anyway since that's not always a solution for everyone. Posted a PR with a fix that works for me locally 👍

@torifat
Copy link
Collaborator

torifat commented Sep 19, 2023

I will have a look. I was thinking about doing something similar to what I did in one of my other project for maximum compatibility.

@duniul
Copy link
Author

duniul commented Sep 19, 2023

Yup, it's pretty much that! 👍

@PyotSiili
Copy link

PyotSiili commented Dec 4, 2023

@torifat
When is the PR addressing this issue scheduled to be merged?
Unfortunately in my project, I cannot use moduleResolution.

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.

3 participants