{"id":13344,"library":"is-browser","title":"is-browser","description":"The `is-browser` package is a minimalist utility designed to determine if the current JavaScript execution environment is a web browser. It exports a single boolean value: `true` if executed in a browser context (detecting `window` and `document` globals), and `false` otherwise (typically in a Node.js environment). The package is at version `2.1.0` and has not received updates since 2018, indicating a mature, stable, but currently unmaintained codebase. Its primary use case is for simple conditional logic in universal JavaScript libraries that need to adapt behavior based on the runtime environment. Unlike more modern alternatives like `browser-or-node` (which offers checks for Web Workers, JSDOM, or Deno), `is-browser` provides only a basic browser vs. non-browser distinction. It has no external runtime dependencies, ensuring a minimal footprint.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/ForbesLindesay/is-browser","tags":["javascript","typescript"],"install":[{"cmd":"npm install is-browser","lang":"bash","label":"npm"},{"cmd":"yarn add is-browser","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-browser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports the boolean value directly as its default export, not as a named export. Avoid destructuring.","wrong":"import { isBrowser } from 'is-browser';","symbol":"isBrowser","correct":"import isBrowser from 'is-browser';"},{"note":"In CommonJS, `require('is-browser')` directly resolves to the exported boolean value, not an object containing it.","wrong":"const { isBrowser } = require('is-browser');","symbol":"isBrowser (CommonJS)","correct":"const isBrowser = require('is-browser');"},{"note":"The export is a boolean, not a function. It should be used directly in conditional statements.","wrong":"if (require('is-browser')()) { /* ... */ }","symbol":"Direct use","correct":"if (require('is-browser')) { /* ... */ }"}],"quickstart":{"code":"import isBrowser from 'is-browser';\n\nfunction setupEnvironmentSpecificFeatures() {\n  if (isBrowser) {\n    console.log('Running in a browser environment. Initializing browser-specific features...');\n    document.addEventListener('DOMContentLoaded', () => {\n      console.log('DOM is ready. Attaching UI event listeners.');\n      // Example: Initialize a client-side analytics library\n      // window.myAnalytics.init(process.env.ANALYTICS_KEY ?? '');\n    });\n  } else {\n    console.log('Running in a Node.js environment. Skipping browser-specific features.');\n    // Example: Connect to a database or perform server-side logging\n    // console.log('Database connection string:', process.env.DATABASE_URL ?? '');\n  }\n}\n\nsetupEnvironmentSpecificFeatures();\n\n// To demonstrate how it works, you might run this in both browser and Node.js\n// In Node.js, `isBrowser` will be false. In a browser, it will be true.","lang":"typescript","description":"Demonstrates how to use `is-browser` to conditionally execute code based on the runtime environment (browser vs. Node.js)."},"warnings":[{"fix":"For more robust and up-to-date environment detection, consider alternatives like `browser-or-node` (version 3.0.0, last updated 2 years ago) which explicitly checks for Web Workers, Deno, and JSDOM.","message":"The package has not been updated since 2018, meaning its environment detection logic may not account for newer JavaScript runtimes, environments (like Deno, Bun, or specific JSDOM setups), or evolving browser global properties. It primarily relies on the presence of `window` and `document`.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Evaluate if the project's long-term stability requires a more actively maintained environment detection library. If strict evergreen compatibility is needed, migrating to a different package is advisable.","message":"Given its age and lack of maintenance, there is a risk of future compatibility issues with new JavaScript language features, module systems, or build tool optimizations. While simple, an unmaintained package can introduce subtle issues over time.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"When using ESM, use `import isBrowser from 'is-browser';` instead of `require`. Ensure your project is configured for ESM or transpiles CommonJS modules correctly.","cause":"Attempting to use `require('is-browser')` in an ECMAScript Module (ESM) context.","error":"ReferenceError: require is not defined"},{"fix":"The `is-browser` package exports a boolean directly. Use it as a variable: `if (isBrowser) { /* ... */ }` or `console.log(isBrowser);`.","cause":"Mistakenly trying to invoke `isBrowser()` as a function, rather than using its direct boolean value.","error":"TypeError: isBrowser is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}