#server only and client only are exact

1 messages · Page 1 of 1 (latest)

glacial spindle
#

so it's makes sense to say: "import server-only" -as a directive - is the opposite of the "use client" directive?

surreal kindle
#

I wouldn’t say they are opposite, but if you import a file that imports a file that (etc etc) imports server-only – if you import that whole tree to a client component then it will blow up at compile time

#

That’s why server-only and client-only are compile-time guards

#

They don’t have any code by themselves, purely empty modules, if you import things at the right place (so that you don’t trigger that compile time guard)

glacial spindle
#

so in your example, if "import server-only" was not used, would the compile not blow up?

surreal kindle
#

The compilation may not blow up. If you also import node-only apis like fs, it will blow up, but if you simply do a fetch using a secret env var for example (that can be run on both the browser and the server) then it wont blow up