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:
[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.
[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:
if (Object.hasOwnThe Object.hasOwn is still an experimental feature and is not supported until Node.js 16.9.0. The configured version range is >=16.0.0.(user, "email")) {
notify(user);
}if (Object.prototype.hasOwnProperty.call(user, "email")) {
notify(user);
}With a newer engines.node, the first example is fine too:
{
"name": "app",
"engines": { "node": ">=18.0.0" }
}if (Object.hasOwn(user, "email")) {
notify(user);
}Options#
| Option | Default | What it does |
|---|---|---|
version | engines.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.
[lint.rules]
"n/no-unsupported-features/es-builtins" = ["error", {
version = ">=20.0.0",
ignores = ["Object.groupBy"],
}]{ "version": ">=20.0.0" }1 problemconst byKind = Object.groupByThe Object.groupBy is still an experimental feature and is not supported until Node.js 21.0.0. The configured version range is >=20.0.0.(items, (item) => item.kind);{ "version": ">=21.0.0" }No problemsconst byKind = Object.groupBy(items, (item) => item.kind);{ "version": ">=20.0.0", "ignores": ["Object.groupBy"] }No problemsconst 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.