es-only
v0.1.0
Published
Runtime-specific imports for modern JavaScript environments - Bun, Deno, Node.js, server-only, and more
Readme
es-only
Runtime-specific imports for modern JavaScript environments.
Installation
npm install es-onlyUsage
Import the environment-specific module to ensure your code only runs in the intended environment:
browser
import 'es-only/browser';
console.log(window.location.href);bun
import 'es-only/bun';
console.log(Bun.version);deno
import 'es-only/deno';
console.log(Deno.version);node
import 'es-only/node';
console.log(process.version);server-only
import 'es-only/server-only';
// This module can only be used in Server Components
// It will throw an error if imported from Client ComponentsHow it works
Each import uses conditional exports to either do nothing (when running in the correct environment) or throw a runtime error (when running in the wrong environment).
