Rules

require-import-extension

Require explicit extensions without guessing module resolution.

Purpose and behavior

Require explicit extensions without guessing module resolution.

Reports extensionless relative and # alias imports, including directory paths. Covers static imports, re-exports and literal dynamic imports. It does not infer .ts versus .tsx or an index filename, so it never autofixes. Bare packages and absolute paths are ignored; explicit asset extensions are allowed.

Options

No configurable options. Enable with "rules/require-import-extension": "error".

Invalid example

import { foo } from './foo'

Valid example

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

Fixes and exceptions

This rule reports diagnostics without an automatic fix. Rewrite the code deliberately rather than guessing its intended semantics.

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

Source and tests

Enabled by the TypeScript preset.

require-import-extension.ts · Tests