unjs/unenv

πŸ•ŠοΈ Node.js compatibility for any JavaScript runtime, including browsers and edge workers.

768

stars

714

commits

TypeScript

primary language

Sep 7, 2026

updated

Browse cluster: Vue.js state management and SSR β†’

README

πŸ•ŠοΈ unenv

npm version npm downloads install size

[!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:

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:

PolyfillsDescriptionSource
unenv/mock/*Mocking utilssrc/runtime/mock
unenv/node/*APIs compatible with Node.js APIsrc/runtime/node
unenv/npm/*NPM package shimssrc/runtime/npm
unenv/polyfill/*Global polyfillssrc/runtime/polyfill
unenv/web/*Subset of Web APIssrc/runtime/web

Node.js compatibility

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

Manual mocking

// 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 */
});

(view source)

Nightly release channel

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

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"
  }
}

License

Published under the MIT license. Made by @pi0 and community πŸ’›


πŸ€– auto updated with automd

Contributors

pi0

463 commits

renovate[bot]

96 commits

vicb

49 commits

jculvey

36 commits

unjs/unenv

πŸ•ŠοΈ Node.js compatibility for any JavaScript runtime, including browsers and edge workers.

768

stars

714

commits

TypeScript

primary language

Sep 7, 2026

updated

Browse cluster: Vue.js state management and SSR β†’

README

πŸ•ŠοΈ unenv

npm version npm downloads install size

[!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:

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:

PolyfillsDescriptionSource
unenv/mock/*Mocking utilssrc/runtime/mock
unenv/node/*APIs compatible with Node.js APIsrc/runtime/node
unenv/npm/*NPM package shimssrc/runtime/npm
unenv/polyfill/*Global polyfillssrc/runtime/polyfill
unenv/web/*Subset of Web APIssrc/runtime/web

Node.js compatibility

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

Manual mocking

// 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 */
});

(view source)

Nightly release channel

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

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"
  }
}

License

Published under the MIT license. Made by @pi0 and community πŸ’›


πŸ€– auto updated with automd

Contributors

pi0

463 commits

renovate[bot]

96 commits

vicb

49 commits

jculvey

36 commits

Languages

TypeScript

82.8%

JavaScript

17.1%