{"id":13880862,"url":"https://github.com/unjs/unenv","last_synced_at":"2025-06-10T22:41:48.339Z","repository":{"id":37015839,"uuid":"313974950","full_name":"unjs/unenv","owner":"unjs","description":"🕊️ Convert javaScript code to be runtime agnostic","archived":false,"fork":false,"pushed_at":"2024-11-21T16:11:38.000Z","size":1626,"stargazers_count":463,"open_issues_count":40,"forks_count":22,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-11-21T17:23:40.744Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-18T15:22:52.000Z","updated_at":"2024-11-21T16:15:29.000Z","dependencies_parsed_at":"2023-07-18T06:11:15.196Z","dependency_job_id":"cda5bcc4-63d1-49fb-8c69-16a2635d0fc1","html_url":"https://github.com/unjs/unenv","commit_stats":{"total_commits":499,"total_committers":27,"mean_commits":18.48148148148148,"dds":0.6092184368737474,"last_synced_commit":"894aa31dc3326dd649d41bc3e6b2c00862dc512e"},"previous_names":["nuxt-contrib/un"],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Funenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Funenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Funenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Funenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/unenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225777407,"owners_count":17522694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:03:33.508Z","updated_at":"2025-06-10T22:41:48.323Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","others"],"sub_categories":[],"readme":"# 🕊️ unenv\n\n\u003c!-- automd:badges color=yellow packagephobia --\u003e\n\n[![npm version](https://img.shields.io/npm/v/unenv?color=yellow)](https://npmjs.com/package/unenv)\n[![npm downloads](https://img.shields.io/npm/dm/unenv?color=yellow)](https://npm.chart.dev/unenv)\n[![install size](https://badgen.net/packagephobia/install/unenv?color=yellow)](https://packagephobia.com/result?p=unenv)\n\n\u003c!-- /automd --\u003e\n\n\u003e [!NOTE]\n\u003e You are on the development (v2) branch. Check out [v1](https://github.com/unjs/unenv/tree/v1) for the current release.\n\nunenv provides polyfills to add [Node.js](https://nodejs.org/) compatibility for any JavaScript runtime, including browsers and edge workers.\n\n## 🌟 Used by\n\n- [Nitro](https://nitro.build/)\n- [Nuxt](https://nuxt.com/)\n- [Cloudflare](https://developers.cloudflare.com/workers/runtime-apis/nodejs/)\n- [ESM.sh](https://esm.sh/)\n\n## Usage\n\nThe `defineEnv` utility can generate a target environment configuration.\n\n```js\nimport { defineEnv } from \"unenv\";\n\nconst { env } = defineEnv({\n  nodeCompat: true,\n  npmShims: true,\n  resolve: true,\n  overrides: {},\n  presets: [],\n});\n\nconst { alias, inject, external, polyfill } = env;\n```\n\nYou can then integrate the env object with your build tool:\n\n\u003cdetails\u003e\n\n| Bundler  | `alias`                                                                       | `inject`                                                                       | `external`                                                               |\n| -------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |\n| rollup   | [`@rollup/plugin-alias`](https://www.npmjs.com/package/@rollup/plugin-alias)  | [`@rollup/plugin-inject`](https://www.npmjs.com/package/@rollup/plugin-inject) | [`external`](https://rollupjs.org/configuration-options/#external)       |\n| rolldown | [`resolve.alias`](https://rolldown.rs/reference/config-options#resolve-alias) | [`inject`](https://rolldown.rs/reference/config-options#inject)                | [`external`](https://rolldown.rs/reference/config-options#external)      |\n| vite     | [`resolve.alias`](https://vite.dev/config/shared-options#resolve-alias)       | [`@rollup/plugin-inject`](https://www.npmjs.com/package/@rollup/plugin-inject) | [`ssr.external`](https://vite.dev/config/ssr-options#ssr-external)       |\n| esbuild  | [`alias`](https://esbuild.github.io/api/#alias)                               | [`inject`](https://esbuild.github.io/api/#inject)                              | [`external`](https://esbuild.github.io/api/#external)                    |\n| rspack   | [`resolve.alias`](https://rspack.dev/config/resolve#resolvealias)             | -                                                                              | [`externals`](https://rspack.dev/config/externals#externals-1)           |\n| webpack  | [`resolve.alias`](https://webpack.js.org/configuration/resolve/#resolvealias) | [`webpack-plugin-inject`](https://www.npmjs.com/package/webpack-inject-plugin) | [`externals`](https://webpack.js.org/configuration/externals/#externals) |\n\n\u003c/details\u003e\n\n### Options\n\n- `nodeCompat`: (default: `true`)\n  - Add `alias` entries for Node.js builtins as `\u003cid\u003e` and `node:\u003cid\u003e`.\n  - Add `inject` entries for Node.js globals `global`, `Buffer`, and `process`.\n- `npmShims`: (default: `false`)\n  - Add `alias` entries to replace npm packages like `node-fetch` with lighter shims.\n- `resolve`: (default: `false`) Resolve config values to absolute paths.\n- `overrides`: Additional overrides for env config.\n- `presets`: Additional presets (for example [`@cloudflare/unenv-preset`](https://npmjs.com/@cloudflare/unenv-preset/)).\n\n### `unenv/` polyfills\n\nYou can also directly import `unenv/` polyfills:\n\n| Polyfills          | Description                        | Source                                                                                 |\n| ------------------ | ---------------------------------- | -------------------------------------------------------------------------------------- |\n| `unenv/mock/*`     | Mocking utils                      | [`src/runtime/mock`](https://github.com/unjs/unenv/tree/main/src/runtime/mock)         |\n| `unenv/node/*`     | APIs compatible with `Node.js` API | [`src/runtime/node`](https://github.com/unjs/unenv/tree/main/src/runtime/node)         |\n| `unenv/npm/*`      | NPM package shims                  | [`src/runtime/npm`](https://github.com/unjs/unenv/tree/main/src/runtime/npm)           |\n| `unenv/polyfill/*` | Global polyfills                   | [`src/runtime/polyfill`](https://github.com/unjs/unenv/tree/main/src/runtime/polyfill) |\n| `unenv/web/*`      | Subset of Web APIs                 | [`src/runtime/web`](https://github.com/unjs/unenv/tree/main/src/runtime/web)           |\n\n## Node.js compatibility\n\n`unenv` replaces Node.js built-in modules compatible with any runtime [(view source)](./src/runtime/node).\n\n\u003cdetails\u003e\n\n\u003c!-- automd:file src=\"./coverage/unenv.md\" --\u003e\n\n- ✅ [node:assert](https://nodejs.org/api/assert.html)\n- ✅ [node:assert/strict](https://nodejs.org/api/assert.html)\n- ✅ [node:async_hooks](https://nodejs.org/api/async_hooks.html)\n- ✅ [node:buffer](https://nodejs.org/api/buffer.html)\n- ✅ [node:child_process](https://nodejs.org/api/child_process.html)\n- ✅ [node:cluster](https://nodejs.org/api/cluster.html)\n- ✅ [node:console](https://nodejs.org/api/console.html)\n- ✅ [node:constants](https://nodejs.org/api/constants.html)\n- ✅ [node:crypto](https://nodejs.org/api/crypto.html)\n- ✅ [node:dgram](https://nodejs.org/api/dgram.html)\n- ✅ [node:diagnostics_channel](https://nodejs.org/api/diagnostics_channel.html)\n- ✅ [node:dns](https://nodejs.org/api/dns.html)\n- ✅ [node:dns/promises](https://nodejs.org/api/dns.html)\n- ✅ [node:domain](https://nodejs.org/api/domain.html)\n- ✅ [node:events](https://nodejs.org/api/events.html)\n- ✅ [node:fs](https://nodejs.org/api/fs.html)\n- ✅ [node:fs/promises](https://nodejs.org/api/fs.html)\n- ✅ [node:http](https://nodejs.org/api/http.html)\n- ✅ [node:http2](https://nodejs.org/api/http2.html)\n- ✅ [node:https](https://nodejs.org/api/https.html)\n- ✅ [node:inspector](https://nodejs.org/api/inspector.html)\n- ✅ [node:inspector/promises](https://nodejs.org/api/inspector.html)\n- ✅ [node:module](https://nodejs.org/api/module.html)\n- ✅ [node:net](https://nodejs.org/api/net.html)\n- ✅ [node:os](https://nodejs.org/api/os.html)\n- ✅ [node:path](https://nodejs.org/api/path.html)\n- ✅ [node:path/posix](https://nodejs.org/api/path.html)\n- ✅ [node:path/win32](https://nodejs.org/api/path.html)\n- ✅ [node:perf_hooks](https://nodejs.org/api/perf_hooks.html)\n- ✅ [node:process](https://nodejs.org/api/process.html)\n- ✅ [node:punycode](https://nodejs.org/api/punycode.html)\n- ✅ [node:querystring](https://nodejs.org/api/querystring.html)\n- ✅ [node:readline](https://nodejs.org/api/readline.html)\n- ✅ [node:readline/promises](https://nodejs.org/api/readline.html)\n- ✅ [node:repl](https://nodejs.org/api/repl.html)\n- ✅ [node:stream](https://nodejs.org/api/stream.html)\n- ✅ [node:stream/consumers](https://nodejs.org/api/stream.html)\n- ✅ [node:stream/promises](https://nodejs.org/api/stream.html)\n- ✅ [node:stream/web](https://nodejs.org/api/stream.html)\n- ✅ [node:string_decoder](https://nodejs.org/api/string_decoder.html)\n- ✅ [node:sys](https://nodejs.org/api/sys.html)\n- ✅ [node:timers](https://nodejs.org/api/timers.html)\n- ✅ [node:timers/promises](https://nodejs.org/api/timers.html)\n- ✅ [node:tls](https://nodejs.org/api/tls.html)\n- ✅ [node:trace_events](https://nodejs.org/api/trace_events.html)\n- ✅ [node:tty](https://nodejs.org/api/tty.html)\n- ✅ [node:url](https://nodejs.org/api/url.html)\n- ✅ [node:util](https://nodejs.org/api/util.html)\n- ✅ [node:util/types](https://nodejs.org/api/util.html)\n- ✅ [node:v8](https://nodejs.org/api/v8.html)\n- ✅ [node:vm](https://nodejs.org/api/vm.html)\n- ✅ [node:wasi](https://nodejs.org/api/wasi.html)\n- ✅ [node:worker_threads](https://nodejs.org/api/worker_threads.html)\n- ✅ [node:zlib](https://nodejs.org/api/zlib.html)\n\n\u003c!-- /automd --\u003e\n\n\u003c/details\u003e\n\n## Manual mocking\n\n\u003cdetails\u003e\n\n```js\n// Magic proxy to replace any unknown API\nimport MockProxy from \"unenv/mock/proxy\";\n\n// You can also create named mocks\nconst lib = MockProxy.__createMock__(\"lib\", {\n  /* overrides */\n});\n```\n\n\u003c/details\u003e\n\n[(view source)](./src/runtime/mock)\n\n## Nightly release channel\n\nYou can use the nightly release channel to try the latest changes in the `main` branch via [`unenv-nightly`](https://www.npmjs.com/package/unenv-nightly).\n\n\u003cdetails\u003e\n\nIf directly using `unenv` in your project:\n\n```json\n{\n  \"devDependencies\": {\n    \"unenv\": \"npm:unenv-nightly\"\n  }\n}\n```\n\nIf using `unenv` via another tool (Nuxt or Nitro) in your project:\n\n```json\n{\n  \"resolutions\": {\n    \"unenv\": \"npm:unenv-nightly\"\n  }\n}\n```\n\n\u003c/details\u003e\n\n## License\n\n\u003c!-- automd:contributors license=MIT author=pi0 --\u003e\n\nPublished under the [MIT](https://github.com/unjs/unenv/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/unenv/graphs/contributors) 💛\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/unjs/unenv/graphs/contributors\"\u003e\n\u003cimg src=\"https://contrib.rocks/image?repo=unjs/unenv\" /\u003e\n\u003c/a\u003e\n\n\u003c!-- /automd --\u003e\n\n\u003c!-- automd:with-automd --\u003e\n\n---\n\n_🤖 auto updated with [automd](https://automd.unjs.io)_\n\n\u003c!-- /automd --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Funenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Funenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Funenv/lists"}