no-absolute-path
Forbid import of modules using absolute paths
💼 This rule is enabled in the following configs: recommended, typescript.
🔧 This rule is automatically fixable by the --fix CLI option.
Rule Details
A module specifier that is an absolute file-system path (/home/me/app/lib/util) only resolves on the machine it was written on. This rule reports one, in every spelling of the module system its option turns on, and the fix rewrites it relative to the file.
esmodule(default on):import ... from, side-effectimport,export ... from,export * from, andimport().commonjs(default on):require('m')with one argument, and TSimport x = require('m').amd(default off): the elements of the dependency array ofdefine([...], factory)andrequire([...], callback). A named module id (define('id', [...], f)) is a name, not a path, and is not checked.
A static template literal (require(`/abs/x`)) is the same string as a quoted one. A specifier the file cannot know (a variable, a template with a substitution) is not checked. Relative and package specifiers are fine.
❌ Incorrect
import util from '/srv/app/lib/util';
export * from '/srv/app/lib/util';
const util2 = require(`/srv/app/lib/util`);✅ Correct
import util from './lib/util';
import lodash from 'lodash';
const load = (name: string) => import(name);Options
[
{
"type": "object",
"properties": {
"esmodule": {
"type": "boolean",
"default": true
},
"commonjs": {
"type": "boolean",
"default": true
},
"amd": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
}
]esmodule(defaulttrue): check ES module syntax.commonjs(defaulttrue): checkrequire()andimport x = require().amd(defaultfalse): check AMD dependency arrays.
When Not To Use It
When absolute specifiers are mapped by your bundler or resolver to something other than the file system (e.g. a / alias for the project root).
Use this rule
npm install -D oxlint-plugin-import-next{ "jsPlugins": ["oxlint-plugin-import-next"], "rules": { "import-next/no-absolute-path": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-import-next'], rules: { 'import-next/no-absolute-path': 'error', }, },});oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.