{"id":10955,"library":"globals","title":"JavaScript Global Identifiers Registry","description":"`globals` is a comprehensive registry of global identifiers found across various JavaScript environments, including browsers, Node.js, Web Workers, and specific frameworks like Vue, Svelte, and Astro. Currently stable at version 17.5.0, the package maintains a frequent release cadence, often monthly, to incorporate updated global lists and introduce new environment definitions. Its core utility is a JSON file (`globals.json`) that maps global variable names to a boolean value, indicating whether the variable is considered writable (`true`) or read-only (`false`), aiding static analysis tools like ESLint. This differentiation is a key feature, allowing linters to flag incorrect assignments to built-in read-only globals. While ESLint 8 and earlier implicitly bundled this package, users of ESLint 9 and later are expected to include `globals` as a direct dependency.","status":"active","version":"17.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/globals","tags":["javascript","globals","global","identifiers","variables","vars","jshint","eslint","environments","typescript"],"install":[{"cmd":"npm install globals","lang":"bash","label":"npm"},{"cmd":"yarn add globals","lang":"bash","label":"yarn"},{"cmd":"pnpm add globals","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a default object containing all environment globals. Named imports for the top-level 'globals' object are incorrect.","wrong":"import { globals } from 'globals';","symbol":"globals","correct":"import globals from 'globals';"},{"note":"For CommonJS environments, `require` returns the full globals object. Destructuring the top-level 'globals' symbol is incorrect.","wrong":"const { globals } = require('globals');","symbol":"globals","correct":"const globals = require('globals');"},{"note":"Environment-specific globals (e.g., `browser`, `node`) are properties of the default `globals` object, not direct named exports.","wrong":"import { browser } from 'globals';","symbol":"globals.browser","correct":"import globals from 'globals'; const browserGlobals = globals.browser;"}],"quickstart":{"code":"import globals from 'globals';\n\n// Access all browser-specific globals\nconsole.log('Browser globals example:');\nconsole.log(Object.keys(globals.browser).slice(0, 5));\n// Expected output: [ 'addEventListener', 'applicationCache', 'ArrayBuffer', 'atob', 'Audio' ]\n\n// Access all Node.js built-in globals (excluding CommonJS module scope)\nconsole.log('\\nNode.js built-in globals example:');\nconsole.log(Object.keys(globals.nodeBuiltin).slice(0, 5));\n// Expected output: [ '__dirname', '__filename', 'Buffer', 'clearImmediate', 'clearInterval' ]\n\n// Check if a specific global is read-only or writable (e.g., 'window' in browser)\nconsole.log(`\\n'window' is writable in browser: ${globals.browser.window}`);\n// Expected output: 'window' is writable in browser: false (or true depending on exact env config)","lang":"javascript","description":"Demonstrates how to import the `globals` object and access environment-specific global identifiers, showing examples for browser and Node.js environments and how to inspect their writability status."},"warnings":[{"fix":"If your linting or analysis tools require `audioWorklet` globals, update your configuration to include `globals.audioWorklet` explicitly or combine it with `globals.browser` as needed.","message":"In version 17.0.0, the `audioWorklet` environment was split from the `browser` environment. Code that previously relied on `globals.browser` to include `audioWorklet` specific globals will now need to explicitly reference `globals.audioWorklet`.","severity":"breaking","affected_versions":">=17.0.0"},{"fix":"Add `\"globals\": \"^17.0.0\"` to your `devDependencies` and ensure your ESLint configuration (e.g., in `eslint.config.js`) correctly references it, such as in `languageOptions.globals`.","message":"For ESLint version 9 and later, the `globals` package is no longer implicitly bundled by ESLint itself. Users must now include `globals` as a direct dependency in their project's `package.json`.","severity":"breaking","affected_versions":">=17.0.0"},{"fix":"Always refer to the package documentation for the precise meaning of the boolean flags. Ensure your linting rules correctly leverage this distinction for read-only vs. writable globals.","message":"The boolean values associated with each global (`true` or `false`) indicate its writability (true for writable, false for read-only) as understood by static analysis tools. Misinterpreting `true` as merely 'exists' rather than 'is writable' can lead to incorrect linter configurations or unexpected behavior when enforcing coding standards.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Regularly update the `globals` package (`npm update globals`) and review release notes for changes relevant to the environments you are targeting. Consider pinning minor versions if strict consistency of global definitions is critical.","message":"The package receives frequent updates to its global lists across various environments. While beneficial for staying current, this means specific global identifiers might be added, removed, or have their writability status changed between minor versions, which could subtly impact linting rules or code analysis if not accounted for.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `import globals from 'globals';` (ESM) or `const globals = require('globals');` (CJS) is present, and verify the environment key (e.g., `browser`, `node`) exists in the `globals` object. Consult `globals.json` for available keys.","cause":"The `globals` object was not correctly imported or required, or an attempt was made to access a non-existent environment key.","error":"TypeError: Cannot read properties of undefined (reading 'browser')"},{"fix":"If your project or file uses ESM (e.g., `\"type\": \"module\"` in `package.json` or `.mjs` files), use `import globals from 'globals';`. If you need to use CommonJS in an ESM project, consider dynamic `import()` or refactoring.","cause":"Attempting to use CommonJS `require()` syntax in an ECMAScript module (ESM) context.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Update `globals` to the latest version (`npm install globals@latest`). For ESLint 9+, ensure `globals` is a direct `devDependency` and explicitly configured in your `eslint.config.js` or `.eslintrc.*` file under `languageOptions.globals` for the relevant environments (e.g., `globals.node`, `globals.browser`).","cause":"The `globals` package is either an outdated version, or ESLint's configuration is not correctly set up to use the `globals` package, especially with ESLint 9+.","error":"ESLint not recognizing new globals or environments (e.g., `BigInt` or `process`)"}],"ecosystem":"npm"}