Is there any better convention than importing server-only?
Answered
Japanese cockle posted this in #help-forum
Japanese cockleOP
Is there any other convention besides installing "server-only" package and importing it in file to declare server only stuff? Is "use server" same as "server-only" or is it only meant for server actions?
6 Replies
server actions use
"use server" and to throw an error for importing into a non server component, you import "server-only"@riský server actions use `"use server"` and to throw an error for importing into a non server component, you import `"server-only"`
Japanese cockleOP
is it the only way to throw an error? Can I somehow avoid installing additional dependencies?
importing
"use server" is the best way to throw errorAnswer
and im pretty sure that it is preinstalled by next anyway [[source](https://www.npmjs.com/package/next?activeTab=dependencies) - and you will see
server-only - it is dev, but most install package managers them also)(but you should still add it to your package.json)