`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 globalsVerified import paths — ran on the pinned version, not inferred.
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.
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.
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`.
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.
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.
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.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.
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`).
No dependency data recorded yet.