# @balena/es-version

> This module provides the ability to specify the default es version to include for balena modules.

Latest version **1.0.4** (published 2026-02-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @balena/es-version
pnpm add @balena/es-version
yarn add @balena/es-version
bun add @balena/es-version
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2026-02-19 |
| First published | 2020-05-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Pagan Gazzard |
| Maintainers | balena.io, page |

## Links

- npm: https://www.npmjs.com/package/@balena/es-version
- Repository: https://github.com/balena-io-modules/balena-es-version
- Homepage: https://github.com/balena-io-modules/balena-es-version#readme
- Issues: https://github.com/balena-io-modules/balena-es-version/issues
- npm.io page: https://npm.io/package/@balena/es-version

## Recent versions

- 1.0.4 (latest) — 2026-02-19
- 1.0.4-build-add-npm-oidc-permissions-c6d7520512a1f915297e8208d53aa4905f690126-1 (build-add-npm-oidc-permissions) — 2026-02-18
- 1.0.3 — 2023-09-06
- 1.0.3-build-es2023-db4a7d2af00194a422431a73e3d57c2f5bd5382e-1 — 2023-09-06
- 1.0.2 — 2022-10-31
- 1.0.2-es-2022-fa3275fbb963e1d6708a20bb9e9ff3de3aae78e7-1 — 2022-10-31
- 1.0.1 — 2021-11-01
- 1.0.1-es-2021-1d48899dd7a111856471d4c482c6dfe0e72abcad — 2021-11-01
- 1.0.0 — 2020-05-29
- 1.0.0-update-dev-deps-6c3550723e8933d6d9ae09c9b91c36d2125812f9 — 2020-05-29
- 1.0.0-initial-version-caa3476bf5895f5a60b75004168c546109f2523d — 2020-05-28
- 1.0.0-initial-version-b454991668b10842e4861a36b6610eae7dd3b25e — 2020-05-28
- 1.0.0-initial-version-a6e9bb183b2aa2ad1555982c51e1040eab971191 — 2020-05-28
- 1.0.0-initial-version-5febf3ddbaed638806b636b09aa5cc4cc5a7e2cd — 2020-05-28
- 1.0.0-initial-version-4336de171f8c57e865b42fd65817c197d2333ff7 — 2020-05-28
- … 1 more at https://npm.io/package/@balena/es-version/versions

## README

# @balena/es-version

This module allows specifying a target es version for other modules to require, currently supported target versions:
* es3 (default)
* es5
* es2015
* es2016
* es2017
* es2018
* es2019
* es2020
* es2021
* es2022
* esnext

## Usage as a client

1. Add @balena/es-version to your package.json with a  `^` version specifier, eg
```json
"@balena/es-version": "^1.0.0",
```
Note: If using locked dependences, eg package-lock.json/npm-shrinkwrap.json/etc, then make sure to also dedupe the module so that the same instance of the module is used everywhere.

2. Within your module require it before anything else and set the desired version:
```js
// Must be set before the first require of an @balena/es-version supporting module
require('@balena/es-version').set('es5');
```
and then the closest matching version will be used by any module that supports choosing the target version, with the priority being:
1. exact match
2. closest match under the desired version
3. lowest supported version

## Usage as a module provider

1. Add @balena/es-version to your package.json with a  `^` version specifier, eg
```json
"@balena/es-version": "^1.0.0",
```

2. Generate builds for the es versions you wish to support along with types for the shim you'll create, eg
```json
"build-es5": "tsc --target es5 --outDir es5",
"build-es2015": "tsc --target es2015 --outDir es2015",
"build-es2018": "tsc --target es2018 --outDir es2018",
"build-types": "tsc --emitDeclarationOnly --outDir .",
"build": "npm run build-es5 && npm run build-es2015 && npm run build-es2018 && npm run build-types",
```

2. Create a shim to use as your entry-point which loads the desired version, eg
```js
// First get the es version to use:
var esVersion = require('@balena/es-version').get(['es5', 'es2015', 'es2018');
// Then include/return the correct version of your module, eg
module.exports = module.exports = require('./' + esVersion);
```
Note: This must be compatible with your lowest supported es version

3. Point your package.json to the new shim and types, eg
```json
"main": "index.js",
"types": "index.d.ts",
```

4. It is also recommended to add a "browser" entry to a fixed es version in your package.json in order to support browser bundlers with default config, eg
```json
"browser": "es5"
```

---
_Source: https://npm.io/package/@balena/es-version · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
