Skip to content

[2.x] Remove package imports from .d.ts file #420

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

Closed
wants to merge 1 commit into from

Conversation

SanderMuller
Copy link
Contributor

Fix: prevent TS errors when unused drivers are not installed

This patch removes global .d.ts references to socket.io-client and pusher-js, preventing TypeScript errors in projects that don’t use these drivers.

Driver-specific types are now only imported in their respective connector files, so they are only type-checked if the connector is explicitly used.

Fixes: #418

@fxnm
Copy link
Contributor

fxnm commented Mar 28, 2025

unfortunately the suggested changes does not resolve the problem.
(I published the changes you proposed into the laravel-echo-fix-issue-415 package)

Error Logs: https://github.com/fxnm/laravel-echo-bug-report/actions/runs/14138980006/job/39616926410

npm run build
Error: node_modules/laravel-echo-fix-issue-415/dist/channel/socketio-channel.d.ts(3,29): error TS2307: Cannot find module 'socket.io-client' or its corresponding type declarations.
Error: node_modules/laravel-echo-fix-issue-415/dist/connector/socketio-connector.d.ts(3,33): error TS2307: Cannot find module 'socket.io-client' or its corresponding type declarations.
Error: Process completed with exit code 2.

@SanderMuller SanderMuller marked this pull request as draft March 28, 2025 22:34
@SanderMuller
Copy link
Contributor Author

unfortunately the suggested changes does not resolve the problem. (I published the changes you proposed into the laravel-echo-fix-issue-415 package)

Error Logs: https://github.com/fxnm/laravel-echo-bug-report/actions/runs/14138980006/job/39616926410

npm run build
Error: node_modules/laravel-echo-fix-issue-415/dist/channel/socketio-channel.d.ts(3,29): error TS2307: Cannot find module 'socket.io-client' or its corresponding type declarations.
Error: node_modules/laravel-echo-fix-issue-415/dist/connector/socketio-connector.d.ts(3,33): error TS2307: Cannot find module 'socket.io-client' or its corresponding type declarations.
Error: Process completed with exit code 2.

@fxnm

I will try to take a look soon. It looks like the combination of requirements is very hard to bring together. Adding type hints for Pusher and SocketIO while they might not be installed.

When a project sets skipLibCheck: false, TypeScript fully type-checks dependencies.
Laravel Echo's .d.ts files currently include import type references to optional packages like socket.io-client and pusher-js.

If those packages are not installed, this causes: TS2307: Cannot find module 'socket.io-client'
Even though the drivers are optional, the .d.ts files assume their presence.

Solution Options and Trade-offs

Approach ✅ Pros ❌ Cons
Peer Dependencies Prevents TS errors by ensuring packages are installed Triggers warnings for users who don’t use the driver (e.g., Reverb)
typesVersions workaround Suppresses type resolution in some scenarios Doesn't work reliably with .d.ts output and skipLibCheck: false
Move imports to driver-specific modules Avoids exposing optional packages in global types Requires users to manually import driver-specific types when needed
Stop generating .d.ts files Eliminates all type resolution errors Users lose IntelliSense and type safety — breaks TypeScript support

@fxnm
Copy link
Contributor

fxnm commented Apr 2, 2025

In my humble option:

  • Stop generating .d.ts files
    is not an option.
  • Move imports to driver-specific modules
    Should theoretically work but would require a lot of labor to implement and maintain.
  • typesVersions workaround
    Unfortunatly does not fully solve the issue

So the only viable option in my option is the Peer Dependencies and it works when I try to build it (with reverb, pusher and socket.io)

The npm warn deprecated lodash.isequal@4.5.0: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. is coming from @inertiajs/react in case you are wondering

Triggers warnings for users who don’t use the driver (e.g., Reverb)

Unfortunately I was not able to trigger any warnings or errors.
Could you please check if this solution would display any warnings on your site?

@SanderMuller
Copy link
Contributor Author

In my humble option:

  • Stop generating .d.ts files
    is not an option.
  • Move imports to driver-specific modules
    Should theoretically work but would require a lot of labor to implement and maintain.
  • typesVersions workaround
    Unfortunatly does not fully solve the issue

So the only viable option in my option is the Peer Dependencies and it works when I try to build it (with reverb, pusher and socket.io)

The npm warn deprecated lodash.isequal@4.5.0: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. is coming from @inertiajs/react in case you are wondering

Triggers warnings for users who don’t use the driver (e.g., Reverb)

Unfortunately I was not able to trigger any warnings or errors. Could you please check if this solution would display any warnings on your site?

As of npm v7, peerDependencies are installed by default. So the downside of using peerDependencies is that it will install it by default (bloat) or warn (yarn / pnpm). It might still be an acceptable solution, though.

@fxnm
Copy link
Contributor

fxnm commented Apr 3, 2025

As of npm v7, peerDependencies are installed by default. So the downside of using peerDependencies is that it will install it by default (bloat) or warn (yarn / pnpm). It might still be an acceptable solution, though.

I agree in any case of errors this change could be reverted

@SanderMuller
Copy link
Contributor Author

Closing in favor of #419 (or accepting the issue)

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 this pull request may close these issues.

Incomplete Bug Fix of "Unable to build application due to missing type declarations. #415"
2 participants