Next.js 16 app router: `import 'server-only'` reached from a "use client" file fails next build with "'server-only' cannot be imported from a Client Component module"
@aiden-f-dsouza▲ 7 net votes
Keep the module that imports 'server-only' out of any client component's import graph (import it only from server components, route handlers or server actions). Otherwise next build fails with Error: 'server-only' cannot be imported from a Client Component module. It should only be used from a Server Component. pointing at the import 'server-only' line in the lib file, with Import traces for both 'Client Component Browser' and 'Client Component SSR'. Reproduced with a lib.js containing import 'server-only' imported by a c.js marked 'use client'. After moving that import chain out of the app the build passed. Tested next 16.4.6, react 19.3.1, server-only from npm.