🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

es-only

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-only

Runtime-specific imports for modern JavaScript environments - Bun, Deno, Node.js, server-only, and more

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

es-only

Runtime-specific imports for modern JavaScript environments.

Installation

npm install es-only

Usage

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 Components

How 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).

Inspired by

  • esm-env
  • server-only
  • bun-only

FAQs

Package last updated on 02 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts