Rules

consistent-import-extension

Normalize code-module import extensions for your runtime.

Purpose and behavior

Normalize code-module import extensions for your runtime.

Checks static imports, re-exports and literal dynamic imports for relative paths and # subpath aliases. In ts mode, .js becomes .ts and .jsx becomes .tsx. In js mode all four code extensions become .js. Missing extensions belong to require-import-extension. Asset extensions, bare packages and absolute paths are ignored. Query strings and fragments are preserved.

Options

{ mode: "ts" } (default) or { mode: "js" }. Configure ["error", { "mode": "js" }] for emitted JavaScript. The examples below use the default ts mode.

Invalid example

import { foo } from './foo.js'

Valid example

import { foo } from './foo.ts'

Fixes and exceptions

This rule supplies an automatic code fix. Review the resulting import bindings and runtime resolution before applying it.

For a genuine boundary exception, use an oxlint-disable-next-line rules/consistent-import-extension -- reason comment. Examples illustrate this rule alone and may omit imports and declarations.

Source and tests

Enabled by the TypeScript preset.

consistent-import-extension.ts · Tests