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 types don't import correctly when using ESM #45

Closed
JstnMcBrd opened this issue Jun 3, 2023 · 1 comment
Closed

Typescript types don't import correctly when using ESM #45

JstnMcBrd opened this issue Jun 3, 2023 · 1 comment

Comments

@JstnMcBrd
Copy link
Contributor

JstnMcBrd commented Jun 3, 2023

I recently migrated one of my projects from JavaScript to TypeScript, and then from CommonJS to EMCAScript modules (ESM).

While you have added types to cleverbot-free, they do not work correctly when using ESM.

Here is an example of the error I am getting.

image

As you can see, the type of cleverbot is not being imported correctly.

I did some research, and found some relevant threads here and here.

It appears that the problem may be fixed by adding "type": "module" to package.json so the types can be interpreted as ESM types.

I modified cleverbot-free's package.json in the node_modules of my project, and it fixed the issue.
image
image

As you can see, the type is now being imported correctly and TypeScript can compile.

Alternatively, you could also fix the problem by changing export default cleverbot to export = cleverbot in index.d.ts, but that might not be backwards-compatible to pre-node16 ESM versions? Not sure.

Here is an additional resource: https://arethetypeswrong.github.io/?p=cleverbot-free%401.1.12

@IntriguingTiles
Copy link
Owner

Resolved via the latter solution in v1.1.13.

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

No branches or pull requests

2 participants