{"id":19999,"library":"eslint-scope","title":"eslint-scope","description":"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.","status":"active","version":"9.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/eslint/js","tags":["javascript","eslint","typescript"],"install":[{"cmd":"npm install eslint-scope","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-scope","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-scope","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"used internally for AST traversal","package":"esrecurse","optional":false},{"reason":"used internally for AST traversal","package":"estraverse","optional":false}],"imports":[{"note":"ESM uses namespace import; default import does not exist.","wrong":"import eslintScope from 'eslint-scope'","symbol":"eslintScope","correct":"import * as eslintScope from 'eslint-scope'"},{"note":"CommonJS requires the full module; destructuring works but namespace import is preferred in ESM.","wrong":"const { analyze } = require('eslint-scope')","symbol":"eslintScope","correct":"const eslintScope = require('eslint-scope')"},{"note":"ScopeManager is a type, not a value; use type import in TypeScript.","wrong":"import { ScopeManager } from 'eslint-scope'","symbol":"ScopeManager","correct":"import type { ScopeManager } from 'eslint-scope'"},{"note":"Scope is an interface; cannot be required as a value.","wrong":"const { Scope } = require('eslint-scope')","symbol":"Scope","correct":"import type { Scope } from 'eslint-scope'"}],"quickstart":{"code":"import * as eslintScope from 'eslint-scope';\nimport * as espree from 'espree';\n\nconst code = `const x = 1; function foo() { var y = 2; }`;\nconst ast = espree.parse(code, { ecmaVersion: 2022, sourceType: 'script' });\nconst scopeManager = eslintScope.analyze(ast, { ecmaVersion: 2022 });\n\nconsole.log(scopeManager.scopes.length); // 2\nconsole.log(scopeManager.globalScope.variables.map(v => v.name)); // ['x', 'foo']\n\nconst functionScope = scopeManager.acquire(ast.body[1]);\nconsole.log(functionScope.variables.map(v => v.name)); // ['y']","lang":"typescript","description":"Parses JavaScript code with espree, analyzes scopes with eslint-scope, and logs global and function scope variables."},"warnings":[{"fix":"Update Node.js to a supported version (20.19.0+, 22.13.0+, or 24+).","message":"Requires Node.js ^20.19.0 || ^22.13.0 || >=24 as of v9.0.0","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Change 'import eslintScope from \"eslint-scope\"' to 'import * as eslintScope from \"eslint-scope\"'.","message":"Default export removed; use namespace import (ESM) or require (CJS)","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Always check that the return value is not null before using it.","message":"ScopeManager.acquire() may return null for nodes that do not introduce a scope","severity":"gotcha","affected_versions":"*"},{"fix":"Avoid relying on optimistic scope analysis; use default behavior.","message":"The 'optimistic' option is experimental and may be removed in future versions","severity":"deprecated","affected_versions":">=7.0.0"},{"fix":"Provide the same ecmaVersion to both the parser and eslint-scope.analyze().","message":"ECMAScript version must match the parser's ecmaVersion; mismatches may cause incorrect scope analysis","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace 'import eslintScope from \"eslint-scope\"' with 'import * as eslintScope from \"eslint-scope\"'.","cause":"Using default import instead of namespace import in ESM","error":"TypeError: eslintScope.analyze is not a function"},{"fix":"Ensure 'eslint-scope' is listed in package.json dependencies and run npm install. For .mjs files, use ESM import syntax.","cause":"Package not installed or wrong import path when using CommonJS with .mjs extension","error":"Cannot find module 'eslint-scope'"},{"fix":"Use scopeManager.acquire(node), not scope.acquire(node).","cause":"Calling acquire on a Scope object instead of ScopeManager","error":"TypeError: scopeManager.acquire is not a function"},{"fix":"Set sourceType to either \"script\" or \"module\" (e.g., sourceType: \"module\").","cause":"Providing an invalid sourceType value","error":"Error: The 'sourceType' option must be \"script\" or \"module\""}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}