Next.js · Middle · Question 15 of 75
How do you guarantee a module with secrets never ends up in the client bundle?
- ✓Correct answer: Add
import 'server-only'to it - 2Name the file with a
.server.tssuffix - 3Put it in the
publicfolder
Explanation
The server-only package causes a build error if the module is imported from a client component. This protects against accidentally leaking DB code or keys. There's a matching client-only package. The .server suffix does nothing in the App Router, and public is served to everyone.