import/no-amd
Disallow AMD define() and require() calls
Also called import-x/no-amd
AMD is RequireJS's module format: define(["dep"], function (dep) { ... }). Bun, Node.js and browsers don't run it without a loader, and tools can't follow its dependencies the way they follow import. In a project that uses ES modules, an AMD call is a leftover.
A call to define or require is reported if it has exactly two arguments and the first is an array. Only calls at the top level of a module are reported, not calls inside a function or a block. A CommonJS require("name") is fine.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"import/no-amd" = "error" # or "warn"Examples#
example.js1 problem
define(["./logger"], function (logger) {Expected imports instead of AMD define().
logger.info("ready");
});example.js1 problem
require(["./logger", "./config"], function (logger, config) {Expected imports instead of AMD require().
logger.info(config.name);
});example.jsNo problems
import logger from "./logger.js";
import config from "./config.js";
logger.info(config.name);example.jsNo problems
const logger = require("./logger");
function loadLegacyPlugin(done) {
require(["./legacy-plugin"], done);
}