biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
Static field initialization accesses __dirname; fix changes timing/scope.
Program
Output
(no stdout) ReferenceError: __dirname 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 __dirname is not defined, causing a ReferenceError before the fix. The fix correctly rewrites to import.meta.dirname, which is the documented replacement for ES modules. The behavior change is due to the module system environment, not a bug in the rewrite itself.
Explanation Nemotron 3 Super unverified
The original code uses `__dirname`, which is only available in CommonJS modules; running it as an ES module throws a ReferenceError because `__dirname` is undefined. The fix replaces `__dirname` with `import.meta.dirname`, which is valid in ES modules and provides the directory name of the current module file. This change avoids the runtime error, allowing the program to execute successfully where it previously failed, thus altering behavior from throwing an exception to completing normally. The rewrite is not semantics-preserving because it changes the program’s outcome from error to success under ES module execution.
Reproduce
- file
prog.js(the before program)- minimized program
- r2-p005.js
- evidence sheet
- r2-p005.md
- regression fixture
- r2-p005.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 · correctness noGlobalDirnameFilename static field · biome rule __dirname replacement · ES module import.meta.dirname usage
- related biomejs/biome/issues/8829 same rule (noGlobalDirnameFilename) but different defect (false negatives vs fix-changes-behavior on static class field)
- related biomejs/biome/pull/8922 same rule (noGlobalDirnameFilename) but different artifact (PR revamping rule vs fix-changes-behavior on static class field)
- related biomejs/biome/issues/11028 same rule (noGlobalDirnameFilename) but different construct (CommonJS module vs ES module static class field)
Details
- program
- Class static field interaction
- hazard
- Static field initialization accesses __dirname; fix changes timing/scope.
- oracle
exit 1 → 0 stderr before: ReferenceError: __dirname is not defined in ES module scope stderr after: (none)- run
- 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (7 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:50.791912323 -0400 +++ fixed.js 2026-10-17 16:16:51.070908997 -0400 @@ -1,5 +1,5 @@ class C { - static dir = __dirname; + static dir = import.meta.dirname; static log() { return C.dir; }
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/")) {}
```