fixhunt

biome correctness/noGlobalDirnameFilename: fix changes program behavior

fix-changes-behaviorlabelled safeprogram-bug · highduplicate
Findings / 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename / r1-p004biome 2.5.156 → 1 lines2026-10-17 20:16 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

async/await ordering, generators and yield position

Program

before
1async function main(){const d=await Promise.resolve(__dirname);console.log(d.length)}main();
after
1async function main(){const d=await Promise.resolve(import.meta.dirname);console.log(d.length)}main();

Output

stdout beforeexit 1
(no stdout)
ReferenceError: __dirname is not defined
stdout afterexit 0
124
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory program-bug · high

The program runs in an ES module environment where __dirname is not defined, causing a ReferenceError before the fix. The fix correctly rewrites __dirname 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 fix itself.

Explanation Nemotron 3 Super unverified

The original code uses `__dirname`, which in Node.js refers to the directory of the current module file; when executed as a script, it resolves to the actual path of `orig.js`. After rewriting, `import.meta.dirname` is used, which only exists in ES modules (`type: "module"`). Since the file is treated as CommonJS (no `"type": "module"` in package.json or `.mjs` extension), `import.meta` lacks a `dirname` property, causing a ReferenceError—though stderr shows none after fix, implying the environment may have silently ignored it or the error was caught elsewhere. However, the observed behavior change—exit code shifting from 1 to 0 and output changing from error to `124`—indicates the fix altered runtime semantics: `__dirname` was valid and produced a string whose length was logged, while the replacement either failed silently or returned a different value (e.g., `undefined`, whose `.length` throws—but stderr after is empty, suggesting the error was suppressed or the value was coerced). In any case, the substitution assumes equivalence between `__dirname` and `import.meta.dirname`, which does not hold in CommonJS contexts, breaking behavior.

Reproduce

file
prog.js (the before program)
minimized program
r1-p004.js
evidence sheet
r1-p004.md
regression fixture
r1-p004.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 · __dirname usage in ES module · Promise resolve import meta dirname · await global dirname replacement

  • duplicate biomejs/biome/issues/11028 same rule (noGlobalDirnameFilename) and same construct (__dirname rewrite in async context) causing ReferenceError

Details

program
Async function awaiting __dirname in expression
hazard
async/await ordering, generators and yield position
oracle
stdout before: stdout after: 124 exit 1 → 0 stderr before: ReferenceError: __dirname is not defined stderr after: (none)
run
2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (6 lines) and the fix's diff
1// Hazard 4
2async function main() {
3 const dir = await Promise.resolve(__dirname);
4 console.log(dir.length);
5}
6main();
--- orig.js	2026-10-17 16:16:40.179040562 -0400
+++ fixed.js	2026-10-17 16:16:40.463037086 -0400
@@ -1,6 +1,6 @@
 // Hazard 4
 async function main() {
-  const dir = await Promise.resolve(__dirname);
+  const dir = await Promise.resolve(import.meta.dirname);
   console.log(dir.length);
 }
 main();
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/")) {}
 ```