-
Notifications
You must be signed in to change notification settings - Fork 281
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
question: Issue when using library in remix/vite and having trouble with the imports #2628
Comments
Hey, @netherglaive, any chance this issue is related to this one? Thank you for raising the issue either way, we'll investigate in the meantime. |
Thanks for the quick response! at a glance it looks like I tried what resolved that one, but let me try again tonight and ill get back to you! |
So there's two parts to this issue, first is that I get: I have my package.json file configured correctly with '{ "type": "module" }' but i dont want to make my route client sided only if I dont have to... is there another work around? |
`import { useCreateChatClient } from 'stream-chat-react'; const apiKey = ''; export default function ChatClient() { if (!client) { Loading... ;} return ; i just put the above in my project and it fails to build even if not placed in any specific component so its happening at build time |
Hey @netherglaive, could you try the following?
StreamChatWrapper.tsx import { useHydrated } from 'remix-utils/use-hydrated';
export function StreamChatWrapper({ children }: { children: React.ReactNode }) {
const isHydrated = useHydrated();
if (!isHydrated) {
// Return a placeholder or loading state for SSR
return <div>Loading chat...</div>;
}
return <>{children}</>;
}
import { lazy, Suspense } from 'react';
import { StreamChatWrapper } from './StreamChatWrapper';
// Dynamically import stream-chat-react components
const StreamChat = lazy(() => import('stream-chat-react').then(module => ({
default: module.StreamChat
})));
export function Chat() {
return (
<StreamChatWrapper>
<Suspense fallback={<div>Loading chat...</div>}>
<StreamChat
// your props
>
{/* your chat components */}
</StreamChat>
</Suspense>
</StreamChatWrapper>
);
vite.config.ts import { defineConfig } from 'vite';
import { vitePlugin as remix } from '@remix-run/dev';
export default defineConfig({
plugins: [remix()],
ssr: {
noExternal: ['stream-chat-react'],
},
});
entry.client.tsx
env.ts export const isServer = typeof window === 'undefined';
export const isClient = !isServer Chat.tsx import { isClient } from '~/utils/env';
export function Chat() {
if (!isClient) {
return <div>Loading chat...</div>;
}
return (
<StreamChatWrapper>
{/* Chat components */}
</StreamChatWrapper>
);
} This all sounds more like a question how to setup remix so that client side code can be hydrated. |
I was able to resolve with the following:
looks like I didnt need the other parts to it, im not sure why 'react-dropzone' is tripping up remix/vite. The styles are missing but ill figure that part out next thanks for the quick support/guidance!! |
I cannot import 'stream-chat-react' in my remix/vite project. I get the error of "Cannot use import statement" outside a module or the other way around when I import during SSR. I'm trying to follow the tutorial with the already created components but im struggling to implement it without a very hacky async import...
Steps to reproduce the behavior:
Create a remix project, then add:
import { Chat, StreamChatOptions, useCreateChatClient } from 'stream-chat-react';
see that during run time SSR fails because of remix/vite complaining that 'export' is not allowed.
Package version
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: