Next.js stability
no-server-only-in-client
Forbid Node-core / DB-driver imports from `"use client"` and `*.client.{ts,tsx}` files.
AI-generated React components routinely `import fs from "fs"` or `import { PrismaClient } from "@prisma/client"` inside a client component. Webpack/Turbopack either crash the build or ship a bundled stub that fails at runtime. Move the call to a server boundary (route handler, server action, server component).
Behavior
- Fixable: No.
- Suggestions: No.
Examples
Bad:
'use client';
import fs from 'fs';Good:
'use server';
import fs from 'fs';Related rules
no-leaked-env-on-clientFlag non-public `process.env.X` reads from `"use client"` or `*.client.{ts,tsx}` files.no-async-useeffectDisallow `useEffect(async () => …)` — returns a Promise instead of a cleanup.no-hydration-mismatchFlag non-deterministic values (`Math.random`, `Date.now`, `new Date()`) inline in JSX.
Use it
Enable no-server-only-in-client in your eslint.config.js:
import deslint from '@deslint/eslint-plugin';
export default [
{
plugins: { deslint },
rules: {
'deslint/no-server-only-in-client': 'error',
},
},
];Found a false positive? Report it on GitHub →