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

Missing dependency for @types/launchdarkly-eventsource #705

Closed
tlevesque-ueat opened this issue Feb 2, 2025 · 14 comments · Fixed by #706
Closed

Missing dependency for @types/launchdarkly-eventsource #705

tlevesque-ueat opened this issue Feb 2, 2025 · 14 comments · Fixed by #706
Assignees
Labels
bug dependencies Pull requests that update a dependency file

Comments

@tlevesque-ueat
Copy link

Describe the bug

Got this error after upgrading from 6.1.3 to 6.4.3:

tsc -b tsconfig.build.json
Error: node_modules/unleash-client/lib/repository/index.d.ts(9,29): error TS7016: Could not find a declaration file for module 'launchdarkly-eventsource'. '/home/runner/work/(redacted)/node_modules/launchdarkly-eventsource/lib/eventsource.js' implicitly has an 'any' type.
Try npm i --save-dev @types/launchdarkly-eventsource if it exists or add a new declaration (.d.ts) file containing declare module 'launchdarkly-eventsource';

Shouldn't @types/launchdarkly-eventsource be listed as a dependency?

Steps to reproduce the bug

In a project using Typescript, upgrade from 6.1.3 to 6.4.3 (not sure when the dependency on launchdarkly-eventsource was introduced, maybe 6.3.0)
Try to compile.

Expected behavior

Should compile without issue

Logs, error output, etc.

Error: node_modules/unleash-client/lib/repository/index.d.ts(9,29): error TS7016: Could not find a declaration file for module 'launchdarkly-eventsource'. '/home/runner/work/(redacted)/node_modules/launchdarkly-eventsource/lib/eventsource.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/launchdarkly-eventsource` if it exists or add a new declaration (.d.ts) file containing `declare module 'launchdarkly-eventsource';`

Screenshots

No response

Additional context

No response

Unleash version

6.4.3

Subscription type

Open source

Hosting type

Hosted by Unleash

SDK information (language and version)

No response

@tlevesque-ueat
Copy link
Author

Oh wait. There isn't a @types/launchdarkly-eventsource package 🤦‍♂

@github-project-automation github-project-automation bot moved this from New to Done in Issues and PRs Feb 2, 2025
@tlevesque-ueat
Copy link
Author

Actually, I think something could still be done to improve the experience.
Right now I need to manually declare the module in a .d.ts file, like this:

declare module 'launchdarkly-eventsource';

This could either be done directly in the unleash-client package, or the import from launchdarkly-eventsource could have a //@ts-ignore to ignore the missing typings.

@tlevesque-ueat tlevesque-ueat reopened this Feb 3, 2025
@github-project-automation github-project-automation bot moved this from Done to New in Issues and PRs Feb 3, 2025
@kwasniew
Copy link
Contributor

kwasniew commented Feb 3, 2025

Hi @tlevesque-ueat. The dependency was added for Unleash to test experimental SSE support. Can you let us know if you're getting this error when using unleash-client-node package as a dependency in your project or building a custom package from the sources yourself?

@Tymek Tymek added question and removed bug labels Feb 3, 2025
@Tymek
Copy link
Member

Tymek commented Feb 3, 2025

@tlevesque-ueat did you try to add node_modules to exclude in your tsconfig.json?

@tlevesque-ueat
Copy link
Author

Hi @tlevesque-ueat. The dependency was added for Unleash to test experimental SSE support. Can you let us know if you're getting this error when using unleash-client-node package as a dependency in your project or building a custom package from the sources yourself?

Hi, I'm using it as a dependency in my project. I'm not using SSE support.

@tlevesque-ueat did you try to add node_modules to exclude in your tsconfig.json?

It's already excluded.

@kwasniew
Copy link
Contributor

kwasniew commented Feb 3, 2025

Can you provide us with a minimal reproduction case so that we can debug it? Ideally a mini setup with package.json and tsconfig that you use?

@kwasniew
Copy link
Contributor

kwasniew commented Feb 3, 2025

BTW we already have // @ts-expect-error on the untyped eventsource library usage itself.

@tlevesque-ueat
Copy link
Author

tlevesque-ueat commented Feb 3, 2025

OK, here's the simplest repro I could make:
https://github.com/tlevesque-ueat/test-unleash-node-client

Build it with npm run compile to see the error.

Basically, I think you just need to import something from unleash-client with noImplicitAny set to true in the TS compilation options.

BTW we already have // @ts-expect-error on the untyped eventsource library usage itself.

Yes, I noticed that. But it doesn't appear in the .d.ts file, which is read by the TS compiler...

@Tymek
Copy link
Member

Tymek commented Feb 3, 2025

Ok, I found the root cause. I'll work on a solution. It's not about noImplicitAny, but about skipLibCheck.

@Tymek Tymek added bug dependencies Pull requests that update a dependency file and removed question labels Feb 3, 2025
@Tymek Tymek self-assigned this Feb 3, 2025
@Tymek Tymek moved this from New to In Progress in Issues and PRs Feb 3, 2025
@Tymek Tymek linked a pull request Feb 3, 2025 that will close this issue
@tlevesque-ueat
Copy link
Author

@Tymek thanks!
Indeed, that works for me.
If you can figure out a way to make that unnecessary, even better! (your PR looks promising, but I'm not really a TS/JS expert...)

@tlevesque-ueat
Copy link
Author

It's not about noImplicitAny, but about skipLibCheck.

Actually, I think it's both. The error will occur if skipLibCheck is false (which is the default) AND noImplicitAny is true.
Setting noImplicitAny to false also fixed the problem for me (but I don't want to, since it also applies to my own code).
Setting skipLibCheck to true is probably the best workaround, with no real downside, since I don't care about checking the types in my dependencies...

@Tymek
Copy link
Member

Tymek commented Feb 4, 2025

Thanks a lot for reproducible example. It helped a lot, and will become a part of our tests.

@Tymek Tymek closed this as completed in #706 Feb 4, 2025
Tymek added a commit that referenced this issue Feb 4, 2025
fix error with dependency types and add test to catch install issues in the future

closes #705
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Feb 4, 2025
@Tymek
Copy link
Member

Tymek commented Feb 4, 2025

Shipped in latest (v6.4.4)

@tlevesque-ueat
Copy link
Author

Thanks for the fix!
Does that mean that with the latest version, I don't need the workarounds (declare module or skipLibCheck)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dependencies Pull requests that update a dependency file
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants