11import Echo from 'laravel-echo'
2- import Pusher from 'pusher-js'
32import type { Channel , Options , ChannelAuthorizationCallback } from 'pusher-js'
43import type { ChannelAuthorizationData } from 'pusher-js/types/src/core/auth/options'
54import { createConsola , type ConsolaInstance } from 'consola'
@@ -11,7 +10,6 @@ import { defineNuxtPlugin, createError, useCookie } from '#app'
1110declare global {
1211 interface Window {
1312 Echo : Echo
14- Pusher : typeof Pusher
1513 }
1614}
1715
@@ -98,9 +96,9 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
9896
9997 const authorizer = config . authentication
10098 ? createAuthorizer (
101- config . authentication as Required < Authentication > ,
102- logger
103- )
99+ config . authentication as Required < Authentication > ,
100+ logger
101+ )
104102 : undefined
105103
106104 // Create a Pusher instance
@@ -133,11 +131,13 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
133131 }
134132}
135133
136- export default defineNuxtPlugin ( ( _nuxtApp ) => {
134+ export default defineNuxtPlugin ( async ( _nuxtApp ) => {
137135 const config = useEchoConfig ( )
138136 const logger = createEchoLogger ( config . logLevel )
139137
140- window . Pusher = Pusher
138+ const pusher = await import ( 'pusher-js' )
139+ // @ts -expect-error Pusher is not defined on Window
140+ window . Pusher = pusher . default || pusher
141141 window . Echo = new Echo ( prepareEchoOptions ( config , logger ) )
142142
143143 logger . debug ( 'Laravel Echo client initialized' )
0 commit comments