SkillAgentSearch skills...

Unenv

🕊️ Node.js compatibility for any JavaScript runtime, including browsers and edge workers.

Install / Use

/learn @unjs/Unenv
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

🕊️ unenv

<!-- automd:badges color=yellow packagephobia -->

npm version npm downloads install size

<!-- /automd -->

[!NOTE] You are on the development (v2) branch. Check out v1 for the current release.

unenv provides polyfills to add Node.js compatibility for any JavaScript runtime, including browsers and edge workers.

🌟 Used by

Usage

The defineEnv utility can generate a target environment configuration.

import { defineEnv } from "unenv";

const { env } = defineEnv({
  nodeCompat: true,
  npmShims: true,
  resolve: true,
  overrides: {},
  presets: [],
});

const { alias, inject, external, polyfill } = env;

You can then integrate the env object with your build tool:

<details>

| Bundler | alias | inject | external | | -------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | | rollup | @rollup/plugin-alias | @rollup/plugin-inject | external | | rolldown | resolve.alias | inject | external | | vite | resolve.alias | @rollup/plugin-inject | ssr.external | | esbuild | alias | inject | external | | rspack | resolve.alias | - | externals | | webpack | resolve.alias | webpack-plugin-inject | externals |

</details>

Options

  • nodeCompat: (default: true)
    • Add alias entries for Node.js builtins as <id> and node:<id>.
    • Add inject entries for Node.js globals global, Buffer, and process.
  • npmShims: (default: false)
    • Add alias entries to replace npm packages like node-fetch with lighter shims.
  • resolve: (default: false) Resolve config values to absolute paths.
  • overrides: Additional overrides for env config.
  • presets: Additional presets (for example @cloudflare/unenv-preset).

unenv/ polyfills

You can also directly import unenv/ polyfills:

| Polyfills | Description | Source | | ------------------ | ---------------------------------- | -------------------------------------------------------------------------------------- | | unenv/mock/* | Mocking utils | src/runtime/mock | | unenv/node/* | APIs compatible with Node.js API | src/runtime/node | | unenv/npm/* | NPM package shims | src/runtime/npm | | unenv/polyfill/* | Global polyfills | src/runtime/polyfill | | unenv/web/* | Subset of Web APIs | src/runtime/web |

Node.js compatibility

unenv replaces Node.js built-in modules compatible with any runtime (view source).

<details> <!-- automd:file src="./coverage/unenv.md" --> <!-- /automd --> </details>

Manual mocking

<details>
// Magic proxy to replace any unknown API
import MockProxy from "unenv/mock/proxy";

// You can also create named mocks
const lib = MockProxy.__createMock__("lib", {
  /* overrides */
});
</details>

(view source)

Nightly release channel

You can use the nightly release channel to try the latest changes in the main branch via unenv-nightly.

<details>

If directly using unenv in your project:

{
  "devDependencies": {
    "unenv": "npm:unenv-nightly"
  }
}

If using unenv via another tool (Nuxt or Nitro) in your project:

{
  "resolutions": {
    "unenv": "npm:unenv-nightly"
  }
}
</details>

License

<!-- automd:contributors license=MIT author=pi0 -->

Published under the MIT license. Made by @pi0 and community 💛 <br><br> <a href="https://github.com/unjs/unenv/graphs/contributors"> <img src="https://contrib.rocks/image?repo=unjs/unenv" /> </a>

<!-- /automd --> <!-- automd:with-automd -->

🤖 auto updated with automd

<!-- /automd -->
View on GitHub
GitHub Stars745
CategoryDevelopment
Updated16h ago
Forks35

Languages

TypeScript

Security Score

95/100

Audited on Mar 27, 2026

No findings