Next.js Discord

Discord Forum

Importing modules accordingly on server and client

Unanswered
American Wirehair posted this in #help-forum
Open in Discord
American WirehairOP
Remix have this way of importing files that are server/client specific by simply specifying .server.ts or .client.ts. Is there a way to make the same on Next?

Tried to dynamically import a server-only code if typeof window === 'undefined' but since this module is also used inside a useEffect in a client component it throws me an error without even executing the code.

Reproduction:
https://codesandbox.io/p/devbox/late-browser-63x7lt

0 Replies