biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
arguments object, function.length, default parameters, rest parameters
Program
Output
(no stdout) ReferenceError: __dirname is not defined in ES module scope
undefined
- 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 rewrite replaces it with import.meta.dirname, which is the correct ES module equivalent, so the behavioral change is due to the module system environment, not a bug in the fix itself.
Explanation Nemotron 3 Super unverified
The original program uses `__dirname`, which is undefined in ES modules, causing a ReferenceError that exits with code 1; the rewritten version substitutes `import.meta.dirname`, which resolves to the directory of the current module file, allowing the function to return a string instead of throwing, so the program prints that path and exits successfully. This changes both output and exit status, altering observable behavior.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p003.js
- evidence sheet
- r1-p003.md
- regression fixture
- r1-p003.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 default parameter · import meta dirname replacement function argument · ES module __dirname undefined error fix
- related biomejs/biome/issues/5778 same rule category (correctness/no*Global) but different construct (process global vs __dirname/__filename)
- related biomejs/biome/issues/9061 same rule category (correctness/no*Global) but different construct (process.env vs __dirname/__filename)
Details
- program
- Function using __dirname in default parameter
- hazard
- arguments object, function.length, default parameters, rest parameters
- oracle
stdout before: stdout after: undefined 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 (5 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:39.716046238 -0400 +++ fixed.js 2026-10-17 16:16:40.007042667 -0400 @@ -1,5 +1,5 @@ // Hazard 3 -function f(dir = __dirname) { +function f(dir = import.meta.dirname) { return dir.length; } console.log(f());
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/")) {}
```