n/no-unsupported-features/es-builtins

Disallow JavaScript built-ins that the Node.js versions you support do not have

Also called node/no-unsupported-features/es-builtins

A built-in that's newer than the oldest Node.js you support doesn't exist there. The code works on your machine and throws for users on the older version.

The rule checks global objects such as WeakRef and their static members such as Object.hasOwn. It takes the versions you support from engines.node in your package.json. If nothing sets a range, it assumes >=16.0.0. Every version in the range must have the built-in.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"n/no-unsupported-features/es-builtins" = "error" # or "warn"

Every option, set to its default. The ones that are commented out are unset by default.

bunfig.toml
[lint.rules]
"n/no-unsupported-features/es-builtins" = ["error", {
  # version = <string>,
  ignores = [], # list of strings
}]

Examples#

Reported, because Node.js has had Object.hasOwn since 16.9.0 and the range starts at 16.0.0:

example.js1 problem
if (Object.hasOwn(user, "email")) {
  notify(user);
}
example.jsNo problems
if (Object.prototype.hasOwnProperty.call(user, "email")) {
  notify(user);
}

With a newer engines.node, the first example is fine too:

package.json
{
  "name": "app",
  "engines": { "node": ">=18.0.0" }
}
example.jsNo problems
if (Object.hasOwn(user, "email")) {
  notify(user);
}

Options#

OptionDefaultWhat it does
versionengines.node, or ">=16.0.0"The range of Node.js versions you support, written as in package.json.
ignores[]Built-ins that are never reported, by the name in the message. Use it for anything you polyfill.

Without version, the range comes from settings.n.version ([lint.settings.n] in bunfig.toml, or settings in an ESLint config), then from engines.node, then from devEngines.runtime in package.json.

bunfig.toml
[lint.rules]
"n/no-unsupported-features/es-builtins" = ["error", {
  version = ">=20.0.0",
  ignores = ["Object.groupBy"],
}]
example.jswith { "version": ">=20.0.0" }1 problem
const byKind = Object.groupBy(items, (item) => item.kind);
example.jswith { "version": ">=21.0.0" }No problems
const byKind = Object.groupBy(items, (item) => item.kind);
example.jswith { "version": ">=20.0.0", "ignores": ["Object.groupBy"] }No problems
const byKind = Object.groupBy(items, (item) => item.kind);

When not to use it#

If a bundler or transpiler adds polyfills for the versions you target, or if the code never runs in Node.js, the reports don't apply.