React · Senior · Question 64 of 75
How do you guarantee a module with secrets is never bundled into client code?
import "server-only";
export async function getSecretData() { /* uses API keys */ }- ✓Correct answer: Import the
server-onlypackage, which makes the build fail if a client module imports this file - 2Name the file
*.server.js - 3Use
'use server'at the top of the file
Explanation
'use server' marks Server Functions callable from the client - it does not hide a module. server-only is a build-time guard against accidental imports.