Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Node 20.11 import.meta info #2254

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/rules/prefer-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ Prefer using the [JavaScript module](https://developer.mozilla.org/en-US/docs/We

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

Replacements:
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).

For most cases in Node.js 20.11 and later:

```js
const __dirname = import.meta.dirname;
const __filename = import.meta.filename;
```

Replacements for older versions:

```js
import {fileURLToPath} from 'node:url';
Expand Down