fixhunt

biome correctness/noGlobalDirnameFilename: fix changes program behavior

fix-changes-behaviorlabelled safeprogram-bug · highrelated
Findings / 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename / r2-p004biome 2.5.1514 → 9 lines2026-10-17 20:16 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

The fix inserts import.meta in a finally block, altering control flow if it throws.

Program

before
1let result = [];
2try {
3 result.push(__dirname);
4} catch (e) {
5 try {
6 } catch (e) {
7 }
8}
9console.log(result.join('|'));
after
1let result = [];
2try {
3 result.push(import.meta.dirname);
4} catch (e) {
5 try {
6 } catch (e) {
7 }
8}
9console.log(result.join('|'));

Output

stdout beforeexit 0
(no stdout)
stdout afterexit 0
<wd>/prog
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory program-bug · high

The fix replaces __dirname with import.meta.dirname, which only exists in ES modules. The program runs as CommonJS (no package.json type: module), so the rewritten code throws a ReferenceError. The behavior change is caused by the module system, not the rewrite itself.

Explanation Nemotron 3 Super unverified

The original uses __dirname which resolves to the directory of the script file being executed; import.meta.dirname refers to the directory of the module containing that expression, which may differ if the script is run as a non-module or via different resolution contexts—here it yields <wd>/prog instead of the expected script directory, changing output.

Reproduce

file
prog.js (the before program)
minimized program
r2-p004.js
evidence sheet
r2-p004.md
regression fixture
r2-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 try block · noGlobalDirnameFilename __dirname replacement · correctness noGlobalDirnameFilename import.meta

  • related biomejs/biome/pull/8922 same rule (noGlobalDirnameFilename) but different construct (revamp to catch false negatives vs fix-changes-behavior in try-catch)
  • related biomejs/biome/issues/8829 same rule (noGlobalDirnameFilename) but different construct (false negatives vs fix-changes-behavior in try-catch)
  • related biomejs/biome/issues/11028 same rule (noGlobalDirnameFilename) but different construct (false positive in CommonJS vs fix-changes-behavior in try-catch)

Details

program
Control flow interference
hazard
The fix inserts import.meta in a finally block, altering control flow if it throws.
oracle
stdout before: stdout after: <wd>/prog
run
2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (14 lines) and the fix's diff
1let result = [];
2try {
3 result.push(__dirname);
4 throw new Error('test');
5} catch (e) {
6 result.push(e.message);
7} finally {
8 try {
9 result.push(import.meta.dirname);
10 } catch (e) {
11 result.push('finally error');
12 }
13}
14console.log(result.join('|'));
--- orig.js	2026-10-17 16:16:50.358917488 -0400
+++ fixed.js	2026-10-17 16:16:50.624914315 -0400
@@ -1,6 +1,6 @@
 let result = [];
 try {
-  result.push(__dirname);
+  result.push(import.meta.dirname);
   throw new Error('test');
 } catch (e) {
   result.push(e.message);
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/")) {}
 ```