file structure behaviour
Answered
sohunn posted this in #help-forum
sohunnOP
I have a next.js 13 app using the App Router and I wish to add some database logic. I remember reading something related to this in the docs but I’m unable to find it again. So I just need a confirmation. If I make a directory named
database outside the app directory, next will never ship those to the client, right?13 Replies
what if you import it to a client component?
the only way to make sure is to hide your ENV variable properly
and make sure you don't use the function inside a client component
@alfon the only way to make sure is to hide your ENV variable properly
sohunnOP
or could i use the package,
server-only and import it in my db related files like the docs suggest?I forgot about server-only
But putting it outside app dir doesnt guarantee server only
@alfon But putting it outside app dir doesnt guarantee server only
sohunnOP
even after using
server-only?i mean, i'm pretty sure that i won't be importing those files in client components
@sohunn even after using `server-only`?
It will throw a build error iirc
Answer
@alfon It will throw a build error iirc
sohunnOP
i think i'll probably play around with it and see what's the behavior. in the end, i'll be making sure its never imported into a client component and since next is server first, its easier to find out if i ever accidentally imported into a client component because of the
use-client directive. anyways, thank you for the quick responses!It throws a build error