# esm-env

> Uses export conditions to return environment information in a way that works with major bundlers and runtimes.

Latest version **1.2.2** (published 2025-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install esm-env
pnpm add esm-env
yarn add esm-env
bun add esm-env
```

## Health

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

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2025-01-08 |
| First published | 2022-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 234 |
| Author | Ben McCann |
| Maintainers | benmccann |

## Links

- npm: https://www.npmjs.com/package/esm-env
- Repository: https://github.com/benmccann/esm-env
- Issues: https://github.com/benmccann/esm-env/issues
- npm.io page: https://npm.io/package/esm-env

## Recent versions

- 1.2.2 (latest) — 2025-01-08
- 1.2.1 — 2024-11-29
- 1.2.0 — 2024-11-27
- 1.1.4 — 2024-10-29
- 1.1.3 — 2024-10-29
- 1.1.2 — 2024-10-29
- 1.1.1 — 2024-10-29
- 1.1.0 — 2024-10-29
- 1.0.0 — 2022-12-05

## README

# esm-env

Uses export conditions to return environment information in a way that works with major bundlers and runtimes.

## Usage

Install with `npm install esm-env`, then import as needed:

```js
import { BROWSER, DEV, NODE } from 'esm-env';
```

Specify `conditions` in your bundler or runtime. For example:
- [Node.js](https://nodejs.org/api/cli.html#-c-condition---conditionscondition)
- [Bun](https://bun.sh/docs/runtime/modules#custom-conditions)
- [Vite/Vitest](https://vite.dev/config/shared-options#resolve-conditions)
- [webpack](https://webpack.js.org/configuration/resolve/#resolveconditionnames)

If `esm-env` is used in both bundled code and an externalized library, you will need to specify conditions both at build-time and run-time.

## Acknowledgements

Thank you to [dominikg](https://github.com/dominikg) for refining the approach used by this library to suggest a more scalable method for adding additional conditions.

## License

[MIT](LICENSE)

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