biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
Rewrite creates import.meta.dirname that shadows a outer-scope dirname variable.
Program
Output
(no stdout) ReferenceError: __dirname is not defined in ES module scope
(no stdout)
- 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 undefined, so it crashes before the fix; after the fix it uses import.meta.dirname which exists in ES modules. The behavior change is caused by the module system, not by a semantic difference in the rewrite itself.
Explanation Nemotron 3 Super unverified
The original program uses `__dirname`, which is undefined in ES modules, causing a ReferenceError when executed. The replacement `import.meta.dirname` provides the directory name of the current module file in ES module scope, resolving the error. Since the original code fails to run due to the missing `__dirname`, while the fixed version executes successfully, the behavior changes from throwing an error to running without error—this difference in observable outcome means the rewrite is not semantics-preserving, even though it makes the code functional in ES modules. The fix alters the program’s execution path by eliminating a runtime exception.
Reproduce
- file
prog.js(the before program)- minimized program
- r2-p003.js
- evidence sheet
- r2-p003.md
- regression fixture
- r2-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 · __dirname usage · ES module global variable · import.meta.dirname replacement
- related biomejs/biome/issues/4331 same rule (noGlobalDirnameFilename) but tracking initial implementation not the fix-changes-behavior defect
- duplicate biomejs/biome/issues/11028 same rule (noGlobalDirnameFilename) and same defect (fix replaces __dirname with import.meta.dirname in contexts where it changes behavior)
Details
- program
- Name collision after rewrite
- hazard
- Rewrite creates import.meta.dirname that shadows a outer-scope dirname variable.
- oracle
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 (6 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:49.925922655 -0400 +++ fixed.js 2026-10-17 16:16:50.190919492 -0400 @@ -1,5 +1,5 @@ let dirname = 'outer'; -const dir = __dirname; +const dir = import.meta.dirname; console.log('dirname:', dirname); if (typeof dirname === 'string') { console.log('block dirname:', dirname);
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/")) {}
```