Registry / testing / eslint-scope

eslint-scope

JSON →
library9.1.2jsnpmunverified

ESLint Scope is the ECMAScript scope analyzer used in ESLint, forked from escope. The current stable version is 9.1.2, with regular releases as part of the ESLint monorepo. It analyzes ESTree-compliant ASTs to produce a ScopeManager with variable scopes, references, and definitions. Key differentiators include deep integration with ESLint, support for JSX, modern ECMAScript features, and both ESM and CommonJS module analysis. It ships with TypeScript types since v9.1.0 and requires Node.js ^20.19.0 || ^22.13.0 || >=24.

npm install eslint-scope
INSTALL
IMPORT
SIG · ESLINT-SCOPE
E
eslint-scope
testingjavascriptv9.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

eslintScope
import * as eslintScope from 'eslint-scope'
import eslintScope from 'eslint-scope'
ESM uses namespace import; default import does not exist.
eslintScope
const eslintScope = require('eslint-scope')
const { analyze } = require('eslint-scope')
CommonJS requires the full module; destructuring works but namespace import is preferred in ESM.
ScopeManager
import type { ScopeManager } from 'eslint-scope'
import { ScopeManager } from 'eslint-scope'
ScopeManager is a type, not a value; use type import in TypeScript.
Scope
import type { Scope } from 'eslint-scope'
const { Scope } = require('eslint-scope')
Scope is an interface; cannot be required as a value.

Parses JavaScript code with espree, analyzes scopes with eslint-scope, and logs global and function scope variables.

import * as eslintScope from 'eslint-scope'; import * as espree from 'espree'; const code = `const x = 1; function foo() { var y = 2; }`; const ast = espree.parse(code, { ecmaVersion: 2022, sourceType: 'script' }); const scopeManager = eslintScope.analyze(ast, { ecmaVersion: 2022 }); console.log(scopeManager.scopes.length); // 2 console.log(scopeManager.globalScope.variables.map(v => v.name)); // ['x', 'foo'] const functionScope = scopeManager.acquire(ast.body[1]); console.log(functionScope.variables.map(v => v.name)); // ['y']
Debug
Known issues
breakingRequires Node.js ^20.19.0 || ^22.13.0 || >=24 as of v9.0.0
fix
Update Node.js to a supported version (20.19.0+, 22.13.0+, or 24+).
affects: >=9.0.0
breakingDefault export removed; use namespace import (ESM) or require (CJS)
fix
Change 'import eslintScope from "eslint-scope"' to 'import * as eslintScope from "eslint-scope"'.
affects: >=5.0.0
gotchaScopeManager.acquire() may return null for nodes that do not introduce a scope
fix
Always check that the return value is not null before using it.
affects: *
deprecatedThe 'optimistic' option is experimental and may be removed in future versions
fix
Avoid relying on optimistic scope analysis; use default behavior.
affects: >=7.0.0
gotchaECMAScript version must match the parser's ecmaVersion; mismatches may cause incorrect scope analysis
fix
Provide the same ecmaVersion to both the parser and eslint-scope.analyze().
affects: *
Errors
Common errors & fixes
TypeError: eslintScope.analyze is not a function
Using default import instead of namespace import in ESM
fix
Replace 'import eslintScope from "eslint-scope"' with 'import * as eslintScope from "eslint-scope"'.
Cannot find module 'eslint-scope'
Package not installed or wrong import path when using CommonJS with .mjs extension
fix
Ensure 'eslint-scope' is listed in package.json dependencies and run npm install. For .mjs files, use ESM import syntax.
TypeError: scopeManager.acquire is not a function
Calling acquire on a Scope object instead of ScopeManager
fix
Use scopeManager.acquire(node), not scope.acquire(node).
Error: The 'sourceType' option must be "script" or "module"
Providing an invalid sourceType value
fix
Set sourceType to either "script" or "module" (e.g., sourceType: "module").
Upgrade
Version history
9.1.2latest on npm
Audit
Dependencies
esrecurserequiredused internally for AST traversal
estraverserequiredused internally for AST traversal
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-scope — npm install eslint-scope · libregistry