# biome correctness/noGlobalDirnameFilename: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: biome 2.5.15
- Rule: correctness/noGlobalDirnameFilename (tool labels the fix: safe, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): program-bug, severity 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.
- Program: minimized from 8 to 7 lines

## Reproducer

```js
let threw = false;
try {
  const d = __dirname;
} catch (e) {
  threw = true;
}
console.log('threw:', threw);
```

## Commands

```sh
node prog.js
bunx @biomejs/biome lint --only=correctness/noGlobalDirnameFilename --write prog.js
node prog.js
```

## Observed

```
stdout before:
threw: true
stdout after:
threw: false
```

## Diff applied by the fix

```diff
--- orig.js	2026-10-22 13:27:41.838234270 -0400
+++ fixed.js	2026-10-22 13:27:41.982236665 -0400
@@ -1,6 +1,6 @@
 let threw = false;
 try {
-  const d = __dirname;
+  const d = import.meta.dirname;
 } catch (e) {
   threw = true;
 }
```

## Why the rewrite is not equivalent (model draft, verify before use)

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.

## Upstream search

Queries: "noGlobalDirnameFilename fix", "__dirname usage in try block", "import.meta.dirname replacement pattern", "noGlobalDirnameFilename rule enforcement"

- related: https://github.com/biomejs/biome/pull/8922
  same rule (noGlobalDirnameFilename) but different defect (revamp for false negatives vs fix-changes-behavior on try/catch)
- related: https://github.com/biomejs/biome/issues/8829
  same rule (noGlobalDirnameFilename) but different defect (false negatives vs fix-changes-behavior on try/catch)

<details><summary>All hits</summary>

- [github, open] 💅 `noUnnecessaryConditions`: false positive on an overloaded call with `undefined` as the default argument (Vue `inject`) — https://github.com/biomejs/biome/issues/12040
- [github, open] 💅 noLeakedRender false positive when using useState<boolean> — https://github.com/biomejs/biome/issues/10790
- [github, closed] 💅 `useSimplifiedLogicExpression` "safe" fix breaks code — https://github.com/biomejs/biome/issues/11351
- [github, closed] 💅 `useExplicitLengthCheck` false positive and broken fix — https://github.com/biomejs/biome/issues/11558
- [github, closed] 💅 `useExplicitLengthCheck` false positive — https://github.com/biomejs/biome/issues/11352
- [github, closed] 💅 Corrupted CLI safe fix for `useConsistentArrowReturn` — https://github.com/biomejs/biome/issues/8347
- [github, closed] 💅 lint/nursery/noUselessUndefined fix is unsafe for functions with union return types — https://github.com/biomejs/biome/issues/6906
- [github, closed] 💅 `useConsistentCurlyBraces` not working with string children — https://github.com/biomejs/biome/issues/7579
- [github, closed] 💅 `noLeakedRender` false positives — https://github.com/biomejs/biome/issues/10514
- [github, closed] 💅 2.1.2 broke SolidJS store syntax — https://github.com/biomejs/biome/issues/6998
- [tavily] biome migrate --write accesses the whole filesystem, takes minutes · Issue #7361 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7361
- [tavily] 💅 useConsistentTypeDefinitions should ignore interfaces in global declarations · Issue #8449 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8449
- [tavily] 💅 `noProcessGlobal` imports from `node::process` instead of `node:process` · Issue #5778 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5778
- [tavily] 💅 [v2] Overrides not working when all linter category rules are on · Issue #5456 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5456
- [tavily] 💅 noNoninteractiveElementInteractions marks `dialog` as non-interactive · Issue #7783 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7783
- [tavily] 💅 False positive by lint/nursery/noUselessUndefined · Issue #6577 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6577
- [tavily] 💅 `noUnresolvedImports`: multiple categories of false positives · Issue #9143 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/9143
- [tavily] 🐛 GritQL pattern doesn't match different kinds of `import` statements · Issue #5801 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5801
- [tavily] React hooks aren't linted if not matching very strict import pattern · Issue #1791 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/1791
- [tavily] 🐛 GritQL pattern `export { $foo } from $source` fails to match while `export * from $source` works · Issue #8828 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8828
- [tavily] 🐛 Ignore pattern in `linter` feature wrongly applies to `formatter` · Issue #2131 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/2131
- [tavily] fix(grit): support positional arguments in pattern, function, and node calls by Zelys-DFKH · Pull Request #10281 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/10281
- [tavily] 🐛 Some ignore pattern generate `ignored file` error · Issue #1471 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/1471
- [tavily] 🐛 GritQL pattern with 2+ metavariables fails to match empty call expression without capturing function parameters · Issue #10242 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/10242
- [tavily] fix(lint): revamp the `noGlobalDirnameFilename` rule to catch many false negatives by siketyan · Pull Request #8922 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/8922
- [tavily] 💅 `noGlobalDirnameFilename` doesn't work in most scenarios (false negatives) · Issue #8829 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8829
- [tavily] 📎 Implement `biome lint --rule=<rule-name>` · Issue #58 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/58

</details>
