Next.js · Server Components · Senior · Best Practice
What does the `server-only` package prevent?
Short Interview Answer
Accidentally importing server-only modules into Client Components.
Detailed Explanation
Importing `server-only` throws at build if a client bundle pulls it in — useful for DB clients and secret helpers. Pair with `client-only` for browser-only modules.
Example
import 'server-only';
export function getDb() { /* ... */ }