# n/no-unsupported-features/es-builtins

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

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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml 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.

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

{/* End of the generated section. */}

## Examples

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

{/* bad */}
```js
if (Object.hasOwn(user, "email")) {
  notify(user);
}
```

Not reported:

{/* good */}
```js
if (Object.prototype.hasOwnProperty.call(user, "email")) {
  notify(user);
}
```

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

{/* file "package.json" */}
```json
{
  "name": "app",
  "engines": { "node": ">=18.0.0" }
}
```

{/* good */}
```js
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`.

```toml bunfig.toml
[lint.rules]
"n/no-unsupported-features/es-builtins" = ["error", {
  version = ">=20.0.0",
  ignores = ["Object.groupBy"],
}]
```

{/* bad {"options": [{"version": ">=20.0.0"}]} */}
```js
const byKind = Object.groupBy(items, (item) => item.kind);
```

{/* good {"options": [{"version": ">=21.0.0"}]} */}
```js
const byKind = Object.groupBy(items, (item) => item.kind);
```

{/* good {"options": [{"version": ">=20.0.0", "ignores": ["Object.groupBy"]}]} */}
```js
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.
