Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.7 KB
Raw Blame
name = "no-node-in-browser"
builtInAgent = "basic-structured"
instruction = """
You are reviewing one TypeScript file from LobeHub's web client: the Vite SPA under `src/` (features, routes, store, services, hooks, components, helpers) or a package module the SPA bundles (React UI, client helpers).

Team rule: code that runs in the browser must not import anything that only exists in Node. The Electron renderer is browser code too — it reaches Node only through IPC.

Oxlint already enforces the deterministic part of this rule (`eslint-core/no-restricted-imports` in oxlint.config.mts): Node built-ins, `@/server/*`, `@/app/(backend)/*`, database models / repositories / clients, and the Node-only subpaths of `@lobechat/heterogeneous-agents`. Do NOT report any of those; they are not your job here.

Your job is the part a path list cannot decide: a THIRD-PARTY npm package whose runtime needs Node, imported as a value. Typical examples: database drivers and ORMs' Node adapters (`pg`, `postgres`, `@neondatabase/serverless` pools, `drizzle-orm/node-postgres`), `ioredis`, `sharp`, `simple-git`, `execa`, `node-pty`, `chokidar`, `electron` main-process APIs (`app`, `BrowserWindow`, `ipcMain`), `server-only`, SDKs documented as Node-only or that read files, spawn processes or open raw sockets.

Anchor the finding on the import line. In the message, name the package and what it needs from Node. In the suggestion, say where the work belongs instead: behind a server endpoint (TRPC/service), behind an Electron IPC call, or in a Node-only entry of the package, with the browser keeping only a pure part (types, parsing, formatting).

Do not report:
- anything ESLint covers (listed above), including workspace aliases (`@/…`, `@lobechat/…`);
- type-only imports: `import type { … }`, `export type { … }`, `typeof import('...')`, and `import { type A, type B } from '…'` where every specifier carries `type` — the repo does not enable `verbatimModuleSyntax`, so these are erased;
- packages that are browser-safe or declare a browser build that Vite resolves (`exceljs`, `jszip`, `pdfjs-dist`, `mammoth`, `drizzle-orm` core and `pg-core` schema builders, `nanoid`, `dayjs`, `zod`, `path-browserify`, `buffer` polyfills, `url` used only for the WHATWG `URL`);
- files that run on the server or outside the browser: Next.js route handlers and shells, middleware / proxy, `instrumentation*`, files that import `server-only`, `*.server.ts`, config files, scripts, and tests.

Report only violations. If an exclusion applies, return no finding; never emit a finding whose message concludes that the import is fine.

If you cannot tell whether the package needs Node at runtime, use low confidence rather than forcing a finding.
"""