Skip to content

Commit eb5af8b

Browse files
Add Node.js 20.11 import.meta info (#2254)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent bb9e788 commit eb5af8b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/rules/prefer-module.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ Prefer using the [JavaScript module](https://developer.mozilla.org/en-US/docs/We
2121

2222
They are [not available in JavaScript modules](https://nodejs.org/api/esm.html#esm_no_filename_or_dirname).
2323

24-
Replacements:
24+
Starting with Node.js 20.11, [`import.meta.dirname`](https://nodejs.org/api/esm.html#importmetadirname) and [`import.meta.filename`](https://nodejs.org/api/esm.html#importmetafilename) have been introduced in ES modules, providing identical functionality to `__dirname` and `__filename` in CommonJS (CJS).
25+
26+
For most cases in Node.js 20.11 and later:
27+
28+
```js
29+
const __dirname = import.meta.dirname;
30+
const __filename = import.meta.filename;
31+
```
32+
33+
Replacements for older versions:
2534

2635
```js
2736
import {fileURLToPath} from 'node:url';

0 commit comments

Comments
 (0)