Next.js · Middle · Question 15 of 75

How do you guarantee a module with secrets never ends up in the client bundle?

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.

Further reading

Problem with a question

Next.js · Middle · question 15

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz