Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rsc-env

LorisSigrist6.9kMIT0.0.2TypeScript support: included

Discriminates between react-server and other environments

rsc, react-server-components, nextjs, next, next-14, app-router, rsc-env, esm-env

readme

RSC-ENV

Inspired by the brilliant esm-env

Uses export conditions to return if the current environment is react-server or not. Bundlers can statically determine the environment at build time & remove dead code.

This is useful for writing utility functions that may be called by either server or client components.

Example

npm install rsc-env
// utils/shared.ts
import { rsc } from "rsc-env";

// This code will be treeshaken from client-component builds
if(rsc) console.log("I'm running in a server component")

License

MIT