biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
comments attached to the removed or moved code
Program
Output
(no stdout) ReferenceError: __filename is not defined in ES module scope
(no stdout)
- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory program-bug · low
The program runs as an ES module where __filename is undefined, causing a ReferenceError before the fix. The rewrite to import.meta.filename is the documented equivalent for ES modules, so the behavior change stems from the module system environment, not a flaw in the fix itself.
Explanation Nemotron 3 Super unverified
The original `__filename` refers to a Node.js CommonJS variable unavailable in ES modules, causing a ReferenceError; replacing it with `import.meta.filename`, which provides the module’s file URL as a string, avoids that error but changes the value type from a filesystem path string to a URL string, altering runtime behavior for any code depending on the exact format or content of `x`. This substitution is not semantically equivalent because the two expressions produce different values despite both being defined.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p008.js
- evidence sheet
- r1-p008.md
- regression fixture
- r1-p008.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js bunx @biomejs/biome lint --only=correctness/noGlobalDirnameFilename --write prog.js node prog.js
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
noGlobalDirnameFilename fix · __filename usage · import.meta.filename replacement · ES module global variable
- related biomejs/biome/issues/6670 same rule area (global __filename/__dirname metavariables) but different construct (GritQL plugin metavariable not set)
- duplicate biomejs/biome/issues/4331 same rule (noGlobalDirnameFilename) and same construct (__filename/__dirname global replacement with import.meta)
Details
- program
- __filename /* inline */ - comment attached to removed code
- hazard
- comments attached to the removed or moved code
- oracle
exit 1 → 0 stderr before: ReferenceError: __filename is not defined in ES module scope stderr after: (none)- run
- 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (3 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:41.596023239 -0400 +++ fixed.js 2026-10-17 16:16:41.866019943 -0400 @@ -1,3 +1,3 @@ // Hazard 8 -const x = __filename /* inline note */; +const x = import.meta.filename /* inline note */; console.log(x.length);
rule documentation given to the models
Summary
- Name: noGlobalDirnameFilename
- Fix: safe
- Default severity: info
- Available from version: 2.0.0
- Diagnostic category: lint/correctness/noGlobalDirnameFilename
Description
Disallow the use of `__dirname` and `__filename` in the global scope.
They are [not available in ES modules](https://nodejs.org/api/esm.html#esm_no_filename_or_dirname).
Starting with Node.js 20.11, `import.meta.dirname` and `import.meta.filename` have been introduced in ES modules, providing identical functionality to `__dirname` and `__filename` in CommonJS (CJS).
Examples
Invalid
```js,expect_diagnostic
const dirname = __dirname;
```
```js,expect_diagnostic
const filename = __filename;
```
``` js,expect_diagnostic
const foo = { __filename }
```
```js,expect_diagnostic
if (__dirname.startsWith("/project/src/")) {}
```
Valid
```js
const dirname = import.meta.dirname
const filename = import.meta.filename
const foo = {__filename: import.meta.filename };
if (import.meta.dirname.startsWith("/project/src/")) {}
```