Registry / testing / globals

globals

JSON →
library0.3.36jsnpmunverified

`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.

npm install globals
INSTALL
IMPORT
SIG · GLOBALS
G
globals
testingjavascriptv0.3.36
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

globals
✓ import globals from 'globals';
✗ import { globals } from 'globals';
The package exports a default object containing all environment globals. Named imports for the top-level 'globals' object are incorrect.
globals
✓ const globals = require('globals');
✗ const { globals } = require('globals');
For CommonJS environments, `require` returns the full globals object. Destructuring the top-level 'globals' symbol is incorrect.
globals.browser
✓ import globals from 'globals'; const browserGlobals = globals.browser;
✗ import { browser } from 'globals';
Environment-specific globals (e.g., `browser`, `node`) are properties of the default `globals` object, not direct named exports.

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.

import globals from 'globals'; // Access all browser-specific globals console.log('Browser globals example:'); console.log(Object.keys(globals.browser).slice(0, 5)); // Expected output: [ 'addEventListener', 'applicationCache', 'ArrayBuffer', 'atob', 'Audio' ] // Access all Node.js built-in globals (excluding CommonJS module scope) console.log('\nNode.js built-in globals example:'); console.log(Object.keys(globals.nodeBuiltin).slice(0, 5)); // Expected output: [ '__dirname', '__filename', 'Buffer', 'clearImmediate', 'clearInterval' ] // Check if a specific global is read-only or writable (e.g., 'window' in browser) console.log(`\n'window' is writable in browser: ${globals.browser.window}`); // Expected output: 'window' is writable in browser: false (or true depending on exact env config)
Debug
Known issues
breakingIn 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`.
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.
affects: >=17.0.0
breakingFor 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`.
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`.
affects: >=17.0.0
gotchaThe 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.
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.
affects: >=1.0.0
gotchaThe 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'browser')
The `globals` object was not correctly imported or required, or an attempt was made to access a non-existent environment key.
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.
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax in an ECMAScript module (ESM) context.
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.
ESLint not recognizing new globals or environments (e.g., `BigInt` or `process`)
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+.
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`).
Upgrade
Version history
0.3.36latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
3
Resources