prefer-import-meta-properties
March 27, 2026 ยท View on GitHub
๐ Prefer import.meta.{dirname,filename} over legacy techniques for getting file paths.
๐ซ This rule is disabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
Starting with Node.js 20.11, import.meta.dirname and import.meta.filename have been introduced in ES modules.
import.meta.filenameis the same as theurl.fileURLToPath()of theimport.meta.url.
import.meta.dirnameis the same as thepath.dirname()of theimport.meta.filename.
This rule replaces legacy patterns with import.meta.{dirname,filename}.
Examples
import path from 'node:path';
import {fileURLToPath} from 'node:url';
// โ
const filename = fileURLToPath(import.meta.url);
// โ
const filename = import.meta.filename;
import path from 'node:path';
import {fileURLToPath} from 'node:url';
// โ
const dirname = path.dirname(fileURLToPath(import.meta.url));
const dirname = path.dirname(import.meta.filename);
const dirname = fileURLToPath(new URL('.', import.meta.url));
// โ
const dirname = import.meta.dirname;