absolute/no-import-meta-path
Disallow deriving filesystem paths from a module's own location, which break when the server is bundled.
#Rule Details
Disallows deriving filesystem paths from a module’s own location: import.meta.dir, import.meta.dirname, import.meta.filename, and fileURLToPath(import.meta.url). These resolve relative to the current file — your src/ tree under absolute dev, but the bundled dist/ under absolute start — so module-relative runtime and data paths silently break in production, and only there, since dev runs from source.
Anchor runtime paths to projectRoot from @absolutejs/absolute (or process.cwd()) instead. The bundler-safe asset form — new URL with a literal path and import.meta.url — is explicitly allowed, as are bare import.meta.url and import.meta.env.
This targets application server code. A library that locates its own shipped assets is a legitimate exception — projectRoot points at the consuming app, not the package — so disable the rule for those files via an override.
#Examples
import.meta path properties
const dir = import.meta.dir;
const file = import.meta.filename;
const dataDir = resolve(import.meta.dir, '..', 'data');fileURLToPath(import.meta.url)
import { fileURLToPath } from 'node:url';
const here = fileURLToPath(import.meta.url);Anchor to projectRoot
import { projectRoot } from '@absolutejs/absolute';
import { join } from 'node:path';
const dbPath = join(projectRoot, 'app.sqlite'); // anchored to the app root// Bundler-safe asset reference — rewritten at build time
const worker = new URL('./worker.js', import.meta.url);
const mode = import.meta.env.MODE; // not a filesystem path
const base = process.cwd(); // also fine#Configuration
Enable this rule in your ESLint configuration:
{
rules: {
'absolute/no-import-meta-path': 'error'
},
overrides: [
{
// A library locating its own shipped assets is a valid exception
files: ['packages/*/src/assets.ts'],
rules: { 'absolute/no-import-meta-path': 'off' }
}
]
}#When Not To Use It
In code that is never bundled — one-off scripts, or a published library that intentionally resolves its own package directory — module-relative paths are safe. Disable the rule for those files instead of globally.