Skip to content

useImportExtensions (since v1.8.0)

Diagnostic Category: lint/nursery/useImportExtensions

Enforce file extensions for relative imports.

Browsers and Node.js do not natively support importing files without extensions. This rule enforces the use of file extensions for relative imports to make the code more consistent.

Tooling also benefits from explicit file extensions, because they do not need to guess which file to resolve.

Rule checks static imports and dynamic imports calls such as import() and require().

import "./foo";
import "./bar/";
import "../";
import "../.";
import("./foo");
require("./foo");
import "biome";
import "./foo.js";
import "./bar/index.js";
import("./foo.js");
require("./foo.js");

If you are using TypeScript, TypeScript version 5.0 and later is required, also make sure to enable allowImportingTsExtensions=true in your tsconfig.json.

Rule does not yet check filesystem for file type. It tries to guess which extension it should add based on the file extension of the current file and the import path. When applying the suggested fix, make sure to verify that the file type is correct.