Skip to content

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

Open
@duniul

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions