Skip to content

Conversation

daltonkyemiller
Copy link

@daltonkyemiller daltonkyemiller commented Mar 10, 2025

Getting an error when types aren't defined in the exports.

import SignatureCanves from "react-signature-canvas";

Diagnostics:
1. Could not find a declaration file for module 'react-signature-canvas'. '/Users/daltonkyemiller/dev/ /node_modules/react-signature-canvas/dist/index.mjs' implicitly has an 'any' type
    There are types at '/Users/daltonkyemiller/dev/ /node_modules/react-signature-canvas/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'react-signature-canvas' library may need to update its package.json or typings. [7016]

TS error screenshot in IDE

This is fixed after adding types to exports.

Copy link
Owner

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Do you have a reproduction for this? What version of TS are you on?
The types work fine for me and TS should fallback to the existing typings field. Although I also deep-dived the TS docs on this recently and there are some ambiguities. Being able to reproduce would be quite helpful

@daltonkyemiller
Copy link
Author

Sure thing!

Happening for me with Typescript v5.7.3 & v5.8.2

https://github.com/daltonkyemiller/repro-react-signature-canvas-126

CleanShot.Mar.10.2025.mp4

@agilgur5
Copy link
Owner

Thanks, I'll take a look soon!

Did you get any CLI errors also? Or only in the IDE?

@daltonkyemiller
Copy link
Author

CLI as well

CleanShot 2025-03-10 at 19 11 12

@agilgur5 agilgur5 changed the title fix: types not resolving unless key is added to exports fix: add types to package.json#exports Mar 11, 2025
@agilgur5
Copy link
Owner

agilgur5 commented Mar 12, 2025

Thanks for the repro, I see what the issue is now!

It appears that my base tsconfig is still on "moduleResolution": "node" -- it was written 3 years ago and appears to predate the newer moduleResolution options by exactly 4 days (TS 4.7 release) apparently 😅 This repo's version of TS similarly predates TS 4.7.
Basically, I need to update some of my dev environments

Both taybenlor/runno#323 (comment) and your repro use the newer bundler option (which is a looser form of node16) and newer TS, which apparently does not fallback to the top-level types/typings field, according to TS maintainers in microsoft/TypeScript#52363 (comment) 1.
Also by experimenting with your repro, I noted that typings does not work inside of package.json#exports, only types does. So I'll need to update some internal references to be consistent with that naming as well.

I'll merge this in now, but give me a bit to update some other pieces and make a new release

Footnotes

  1. see also https://github.com/microsoft/TypeScript/issues/46334 and https://github.com/arethetypeswrong/arethetypeswrong.github.io

@agilgur5 agilgur5 enabled auto-merge (squash) March 12, 2025 00:29
@agilgur5 agilgur5 added kind: bug scope: types Related to type definitions labels Mar 12, 2025
@agilgur5 agilgur5 changed the title fix: add types to package.json#exports fix(pkg): add types to package.json#exports Mar 12, 2025
@agilgur5 agilgur5 disabled auto-merge March 12, 2025 00:31

This comment was marked as resolved.

@agilgur5
Copy link
Owner

This and the follow-up fix in #131 have been released in v1.1.0-alpha.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug scope: types Related to type definitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants