Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>dotenv-scannerNew to Visual Studio Code? Get it now.
dotenv-scanner

dotenv-scanner

Mahdi

|
3 installs
| (0) | Free
Scan the workspace for environment variables used in JavaScript and TypeScript that are missing from .env files.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Dotenv Scanner

Dotenv Scanner helps you keep environment variables in your JavaScript and TypeScript projects in sync with your .env files. It scans variable references in source files and definitions in .env files, then shows problems directly in VS Code.

Environment variable mistakes are easy to miss during development: code can refer to a variable that was never added to a .env file, while an old .env entry can remain after the code stops using it. Dotenv Scanner makes both cases visible where you work, so you can find missing configuration and clean up unused entries before they cause confusion.

What it reports

Problem Where it appears Default severity
A source file references a variable that is not defined in any workspace .env file On the reference's line in the source file Error
A variable defined in a .env file is not referenced by a scanned source file On the definition's line in the .env file Warning

For example, if your code contains process.env.API_URL but no scanned .env file defines API_URL, the source file gets an error. If a .env file defines OLD_TOKEN and no scanned source file uses it, the .env file gets a warning.

The scanner recognizes process.env.NAME and import.meta.env.NAME, including quoted bracket access such as process.env["NAME"]. It reads variable definitions in the form NAME=value or export NAME=value. By default, it scans .js, .jsx, .ts, .tsx, and .mjs source files. Source directories and extensions can be configured.

Ignoring a file

Use a file-level comment when a file intentionally cannot be checked. The directive can appear anywhere in the file.

// dotenv-scanner-ignore
const generatedValue = process.env.DYNAMIC_ENV_NAME;

dotenv-scanner-ignore hides missing-variable diagnostics for that source file. To hide unused-variable warnings for an entire .env file, add:

# dotenv-scanner-ignore-unused
GENERATED_AT_BUILD=value

Getting started

  1. Install Dotenv Scanner in VS Code and open your project as a workspace.
  2. The extension discovers configured source files after activation and scans them in a background worker. Open or edit a source file to see its diagnostics update immediately.
  3. Open View → Problems (or press Ctrl+Shift+M on Windows/Linux, Cmd+Shift+M on macOS). Look for diagnostics with the source Dotenv Scanner. Select one to jump to the relevant line.
  4. Fix the source reference or .env definition. Changed and newly-created source files are reparsed individually; deleted files have their diagnostics removed. When an .env file changes, cached references are revalidated without reparsing source files.

Background scanning

At startup, Dotenv Scanner discovers source files that match your configured directories and extensions. Their environment-variable references are parsed by one background worker with a bounded queue, keeping parsing work off the VS Code extension host.

After the initial scan, it watches only matching source files. A source-file create or change reparses that file only; deletion removes its diagnostics. Unsaved editor changes are debounced. Changes to .env or .env.* files reload defined variable names and revalidate the cached references without rereading or reparsing source files.

Unused .env variable warnings require a complete workspace comparison and are therefore refreshed by Scan .env Files, rather than during every file change.

To run a scan on demand, open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P) and use:

  • Dotenv Scanner: Scan .env Files — scans all configured source files and all .env files. It refreshes both missing-variable errors and unused-variable warnings, then shows the unused variable names in a confirmation message.
  • Dotenv Scanner: Scan Files — scans all configured source files for process.env.* and import.meta.env.* references. It refreshes missing-variable diagnostics and shows the variable names that are not defined in any .env file.

The Problems view is the place to see each issue by file and line; command messages are only summaries. Both commands perform a full workspace scan, so use them when you need a complete result immediately rather than waiting for incremental background scanning.

Configuration

Configure Dotenv Scanner in VS Code's Settings UI or your workspace's .vscode/settings.json:

{
  "dotenv-scanner.undefinedVariables.directories": ["^src(?:/.*)?$"],
  "dotenv-scanner.undefinedVariables.extensions": ["ts", "tsx", "js", "jsx", "mjs"],
  "dotenv-scanner.undefinedVariables.severity": "warning"
}
Setting Default Purpose
dotenv-scanner.undefinedVariables.directories [".*"] Regular expressions matched against workspace-relative source directories. Use .* to scan all directories, including the workspace root.
dotenv-scanner.undefinedVariables.extensions ["ts", "tsx", "js", "jsx", ".mjs"] Source file extensions to scan. A leading dot is optional.
dotenv-scanner.undefinedVariables.severity "error" Severity of missing-variable diagnostics: error, warning, information, or hint.

The directory and extension settings affect which source files are checked for both missing and unused variables. Unused .env variables are always reported as warnings.

Controlling error files

Missing-variable diagnostics are reported only in source files that match both undefinedVariables.directories and undefinedVariables.extensions. For example, this configuration reports errors only in TypeScript files inside src/:

{
  "dotenv-scanner.undefinedVariables.directories": ["^src(?:/.*)?$"],
  "dotenv-scanner.undefinedVariables.extensions": ["ts", "tsx"],
  "dotenv-scanner.undefinedVariables.severity": "error"
}

Use severity: "warning", "information", or "hint" to change how missing-variable problems appear. To exclude one generated or dynamic source file without changing the workspace scope, add // dotenv-scanner-ignore anywhere in that file.

Scope

Dotenv Scanner checks variable names found in files in the open workspace. It supports direct process.env and import.meta.env references; references built dynamically at runtime cannot be resolved by this scan. A variable defined in any scanned .env file counts as defined for the workspace.

Release notes

0.1.1

  • Expanded command, error-file scope, format configuration, and ignore-directive guidance.

0.1.0

  • Added background, incremental workspace scanning and cached .env revalidation.
  • Added file-level ignore directives and a large-workspace stress test.
  • Added VSIX packaging support.

0.0.2

  • Added worker-backed, bounded initial scanning for missing environment variables.
  • Added incremental source-file scanning, cached reference revalidation, and stale-result protection.
  • Kept unused-variable checks in the explicit full .env scan command.

0.0.1

Initial release: workspace diagnostics for missing and unused environment variables, on-demand scan commands, and configurable source scanning and missing-variable severity.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft