biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
If __dirname access throws (hypothetical), the fix removes the try/catch scope.
Program
Output
threw: true
threw: false
- 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 in a CommonJS environment where __dirname exists but import.meta.dirname does not, so the original code catches a ReferenceError and logs threw: true. After the fix, the rewritten code uses import.meta.dirname which throws in CommonJS, but the oracle shows threw: false, indicating the execution environment changed or the test setup differs. The rule's fix is only correct for ES modules; applying it in CommonJS changes behavior due to module system differences, not a flaw in the rule itself.
Explanation Nemotron 3 Super unverified
The original code uses `__dirname`, which in CommonJS resolves to the directory of the current file; if unavailable (e.g., in certain module contexts), it throws a ReferenceError, caught and setting `threw` to true. The replacement `import.meta.dirname` is an ES module property that is only available when the code is parsed as an ES module; in environments where it is undefined or inaccessible, accessing it may still throw—but here, the environment likely supports it without error, so no exception occurs, `threw` remains false, and the output changes. The rewrite assumes semantic equivalence, but `__dirname` and `import.meta.dirname` differ in availability and scoping across module systems, making the substitution unsafe in this context.
Reproduce
- file
prog.js(the before program)- minimized program
- r2-p002.js
- evidence sheet
- r2-p002.md
- regression fixture
- r2-p002.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 · import.meta.dirname replacement pattern · noGlobalDirnameFilename rule enforcement
- related biomejs/biome/pull/8922 same rule (noGlobalDirnameFilename) but different defect (revamp for false negatives vs fix-changes-behavior on try/catch)
- related biomejs/biome/issues/8829 same rule (noGlobalDirnameFilename) but different defect (false negatives vs fix-changes-behavior on try/catch)
Details
- program
- Exception during evaluation
- hazard
- If __dirname access throws (hypothetical), the fix removes the try/catch scope.
- oracle
stdout before: threw: true stdout after: threw: false- run
- 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (8 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:49.500927738 -0400 +++ fixed.js 2026-10-17 16:16:49.762924605 -0400 @@ -1,6 +1,6 @@ let threw = false; try { - const d = __dirname; + const d = import.meta.dirname; if (d === undefined) throw new Error('unexpected'); } catch (e) { threw = true;
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/")) {}
```