Skip to content

noAmd (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noAmd": "error"
}
}
}
}

Disallow AMD require() and define() calls.

AMD (Asynchronous Module Definition) is an older way to split code into modules. It needs a loader library, such as RequireJS, and declares the modules a file depends on as a list of names passed to define() or require(). Standard import and export statements work in all modern browsers and Node.js without an extra library, and editors and bundlers can understand them without running the code.

This rule reports calls to define() and require() that receive exactly two arguments when the first one is an array, such as define(["a"], function (a) {}). It only reports calls at the top level of a file, outside of functions and blocks. Calls to a define or require function declared in your own code aren’t reported, and neither are CommonJS calls such as require("a").

This rule is useful while moving a codebase from AMD to standard modules.

define(["a", "b"], function (a, b) {});
code-block.js:1:1 lint/nursery/noAmd ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This define() call loads modules with AMD instead of import statements.

> 1 │ define(["a", "b"], function (a, b) {});
│ ^^^^^^
2 │

ℹ AMD needs a loader library to run, while import and export statements work everywhere and can be understood by tools without running the code.

ℹ Load each module in the list with an import statement instead, such as import a from "a".

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

require(["a", "b"], function (a, b) {});
code-block.js:1:1 lint/nursery/noAmd ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This require() call loads modules with AMD instead of import statements.

> 1 │ require(["a", "b"], function (a, b) {});
│ ^^^^^^^
2 │

ℹ AMD needs a loader library to run, while import and export statements work everywhere and can be understood by tools without running the code.

ℹ Load each module in the list with an import statement instead, such as import a from "a".

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import a from "a";
const b = require("b");
  • If you want to disallow CommonJS require() and module.exports too, see noCommonJs.