> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# lib.syntax

- **Type:**

```ts
type EcmaScriptVersion =
  | 'es5'
  | 'es6'
  | 'es2015'
  | 'es2016'
  | 'es2017'
  | 'es2018'
  | 'es2019'
  | 'es2020'
  | 'es2021'
  | 'es2022'
  | 'es2023'
  | 'es2024'
  | 'es2025'
  | 'esnext';

type Syntax = EcmaScriptVersion | string[];
```

- **Default:**
  - `['node >= <minimum-version>']` when [output.target](/config/rsbuild/output.md#outputtarget) is `'node'` and `package.json#engines.node` declares an inferable minimum Node.js version
  - Otherwise, `'esnext'`
- **CLI:** `--syntax <value>` (repeatable, e.g. `--syntax es2018` or `--syntax="node 14" --syntax="Chrome 103"`)
- **Top-level config:** Supported

Configure the syntax to which JavaScript and CSS will be downgraded.

See [Output Compatibility - Syntax Downgrade](/guide/advanced/output-compatibility.md) for more details.

## Default behavior

When [output.target](/config/rsbuild/output.md#outputtarget) is set to `'node'` and `syntax` is not configured, Rslib tries to infer the syntax target from `package.json#engines.node`. If `package.json` declares an inferable `engines.node` range, Rslib uses the minimum Node.js version from that range as the syntax target.

```json title="package.json"
{
  "engines": {
    "node": "^20.19.0 || >=22.12.0"
  }
}
```

The config above is equivalent to:

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: ['node >= 20.19.0'],
    },
  ],
};
```

In other cases, Rslib defaults to `'esnext'`. This means the output targets only the latest versions of mainstream browsers (Chrome / Firefox / Edge / macOS Safari / iOS Safari) or the latest Node.js version, depending on [output.target](/config/rsbuild/output.md#outputtarget).

To override this default behavior, set `syntax` explicitly.

## Set ECMAScript version

You can set the ECMAScript version directly, such as `es2015`, `es2022`, etc.

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: 'es2015',
    },
  ],
};
```

## Set browserslist query

You can also set the [Browserslist query](https://browsersl.ist/), such as `last 2 versions`, `> 1%`, `node >= 16`, `chrome >= 80`, etc.

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: ['last 2 versions', '> 1%'],
    },
  ],
};
```

## Mix ECMAScript version and browserslist query

You can also mix ECMAScript version and Browserslist query, such as `es2015` and `node 20`. Rslib will turn ECMAScript Version into Browserslist query, and then merge them together.

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      syntax: ['es2015', 'node 20'],
    },
  ],
};
```
