Next.js: server-only module accidentally imported in Client Component
Build detects unauthorised import of server-only module into the component from use client. The module can read secrets or Node APIs and must not be placed in the browser Bundle.
How to identify the source of the problem
Identify the import chain leading from Client Component to the server file. See if the function in the module takes token, connects to the base or uses process.env without NEXT PUBLUC .
Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.
Repair steps
Transfer sensitive logic to Server Component, Server Action or Route Handler, and transfer only the permitted data to the customer. Mark confidential modules with server-only import and separate types from runtime function so random import does not return.
How to Test Solution
The compilation passes and the secret key does not appear in the Bundle downloaded by the browser.
Security and restrictions
Do not replace server-only by NEXT PUBLIC when using private token.