import/imports-first

Require all imports to come before every other statement (old name of import/first)

deprecatedfixable

Also called import-x/imports-first

This is the old, deprecated name of import/first. It does the same thing and takes the same options. Use import/first instead.

Imports are hoisted. The imported modules load and run before any line of the file that imports them, no matter where the import is written. An import below other code looks like it runs later, but it doesn't.

--fix moves the imports to the top, after the ones that are already there.

Examples#

example.js1 problem
import { loadConfig } from "./config.js";

loadConfig(); // runs after "./server.js" has loaded, not before

import { startServer } from "./server.js";

startServer();
example.jsNo problems
import { loadConfig } from "./config.js";
import { startServer } from "./server.js";

loadConfig();
startServer();

Options#

OptionWhat it does
"disable-absolute-first" (default)Imports can be in any order.
"absolute-first"Also report an import of a package, or any path that doesn't start with ., after a relative import.
example.jswith "absolute-first"1 problem
import { loadConfig } from "./config.js";
import express from "express";