Subscription error: TRPCClientError: Subscriptions should use wsLink
this is my trpc client:
I don't know what is the issue exactly.
export const trpc = createTRPCNext<AppRouter>({
/**
* @link https://trpc.io/docs/v11/ssr
*/
// ssr: true,
// ssrPrepass,
ssr: false,
config({ ctx }) {
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/v11/ssr
*/
return {
/**
* @link https://trpc.io/docs/v11/client/links
*/
links: [
// adds pretty logs to your console in development and logs errors in production
loggerLink({
enabled: opts =>
(process.env.NODE_ENV === 'development' && typeof window !== 'undefined') ||
(opts.direction === 'down' && opts.result instanceof Error)
}),
splitLink({
condition: op => {
return op.type === 'subscription'
},
true: wsLink({
client: createWSClient({
url: 'ws://localhost:3001'
})
}),
false: httpBatchLink({
transformer: superjson,
url: `http://localhost:3000/api/trpc`
})
})
],
/**
* @link https://tanstack.com/query/v5/docs/reference/QueryClient
*/
queryClientConfig: { defaultOptions: { queries: { staleTime: 60 } } }
}
},
/**
* @link https://trpc.io/docs/v11/data-transformers
*/
transformer: superjson
})export const trpc = createTRPCNext<AppRouter>({
/**
* @link https://trpc.io/docs/v11/ssr
*/
// ssr: true,
// ssrPrepass,
ssr: false,
config({ ctx }) {
/**
* If you want to use SSR, you need to use the server's full URL
* @link https://trpc.io/docs/v11/ssr
*/
return {
/**
* @link https://trpc.io/docs/v11/client/links
*/
links: [
// adds pretty logs to your console in development and logs errors in production
loggerLink({
enabled: opts =>
(process.env.NODE_ENV === 'development' && typeof window !== 'undefined') ||
(opts.direction === 'down' && opts.result instanceof Error)
}),
splitLink({
condition: op => {
return op.type === 'subscription'
},
true: wsLink({
client: createWSClient({
url: 'ws://localhost:3001'
})
}),
false: httpBatchLink({
transformer: superjson,
url: `http://localhost:3000/api/trpc`
})
})
],
/**
* @link https://tanstack.com/query/v5/docs/reference/QueryClient
*/
queryClientConfig: { defaultOptions: { queries: { staleTime: 60 } } }
}
},
/**
* @link https://trpc.io/docs/v11/data-transformers
*/
transformer: superjson
})I don't know what is the issue exactly.