Skip to content

Clear server vs client boundary

Tag every lib `scope:server`, `scope:client`, or `scope:isomorphic` — enforce at the bundler boundary.

nx-isolation-deps-server-client-boundary

Why it matters

Failure modes if this rule is ignored
StakeIf ignored
Secret exposure
  • Server code leaking to client = bloated bundle, or worse, secret leak.
Layer mixing
  • Client code leaking to server = runtime errors on window.

How to fix

In a monorepo with backend and frontend apps, every library must declare which side it runs on. A "both" library is one the bundler will catch importing fs in production. Tag libs scope:server, scope:client, or scope:isomorphic and enforce via enforce-module-boundaries.

Examples

Bad
ts
// libs/shared/utils/src/lib/index.ts
export { formatDate } from './format-date';      // browser-safe
export { signJWT }    from './sign-jwt';         // server-only, uses crypto
export { parseCSV }   from './parse-csv';        // browser-safe
Good
text
/libs/shared
  /util-formatting    [scope:isomorphic]    # both sides
  /util-server        [scope:server]        # backend only
  /util-browser       [scope:client]        # frontend only

Contribute

Released under the MIT License.

esc