# vite-plugin-node-polyfills

> A Vite plugin to polyfill Node's Core Modules for browser environments.

Latest version **0.28.0** (published 2026-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-node-polyfills
pnpm add vite-plugin-node-polyfills
yarn add vite-plugin-node-polyfills
bun add vite-plugin-node-polyfills
```

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.28.0 |
| Published | 2026-05-18 |
| First published | 2022-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 528.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 424 |
| Author | David Myers |
| Maintainers | davidmyersdev |
| Keywords | node, node-core-modules, node-polyfills, node-stdlib, polyfills, vite, vite-plugin |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-node-polyfills
- Repository: https://github.com/davidmyersdev/vite-plugin-node-polyfills
- Issues: https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues
- Funding: https://github.com/sponsors/davidmyersdev
- npm.io page: https://npm.io/package/vite-plugin-node-polyfills

## Dependencies (2)

- [node-stdlib-browser](https://npm.io/package/node-stdlib-browser.md) ^1.3.1
- [@rollup/plugin-inject](https://npm.io/package/@rollup/plugin-inject.md) ^5.0.5

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.28.0 (latest) — 2026-05-18
- 0.27.0 — 2026-05-15
- 0.26.0 — 2026-03-29
- 0.25.0 — 2026-01-15
- 0.24.0 — 2025-07-06
- 0.23.1 — 2025-07-05
- 0.23.0 — 2025-01-19
- 0.22.0 — 2024-05-19
- 0.21.0 — 2024-02-11
- 0.20.0 — 2024-02-09
- 0.19.0 — 2023-12-27
- 0.18.0 — 2023-12-22
- 0.17.0 — 2023-11-29
- 0.16.0 — 2023-11-04
- 0.15.0 — 2023-10-01
- … 30 more at https://npm.io/package/vite-plugin-node-polyfills/versions

## README

[![Sponsor me](https://img.shields.io/badge/sponsor-DB61A2?style=for-the-badge&logo=GitHub-Sponsors&logoColor=white)](https://voracious.link/sponsor)
[![Donate](https://img.shields.io/badge/donate-FF5F5F?style=for-the-badge&logo=ko-fi&logoColor=white)](https://voracious.link/donate)

# vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments. Supports [`node:` protocol imports](https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#node-imports).

## Why do I need this?

```
Module "stream" has been externalized for browser compatibility. Cannot access "stream.Readable" in client code.
```

Since browsers do not support Node's [Core Modules](https://nodejs.org/dist/latest-v16.x/docs/api/modules.html#core-modules), packages that use them must be polyfilled to function in browser environments. In an attempt to prevent runtime errors, Vite produces [errors](https://github.com/vitejs/vite/issues/9200) or [warnings](https://github.com/vitejs/vite/pull/9837) when your code references builtin modules such as `fs` or `path`.

## Getting Started

Install the package as a dev dependency.

```sh
# npm
npm install --save-dev vite-plugin-node-polyfills

# pnpm
pnpm install --save-dev vite-plugin-node-polyfills

# yarn
yarn add --dev vite-plugin-node-polyfills
```

Add the plugin to your `vite.config.ts` file.

```ts
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    nodePolyfills(),
  ],
})
```

### Customizable when you need it

The following options are available to customize it for your needs.

```ts
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    nodePolyfills({
      // To add only specific polyfills, add them here. If no option is passed, adds all polyfills
      include: ['path'],
      // To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effect
      exclude: [
        'http', // Excludes the polyfill for `http` and `node:http`.
      ],
      // Whether to polyfill specific globals.
      globals: {
        Buffer: true, // can also be 'build', 'dev', or false
        global: true,
        process: true,
      },
      // Override the default polyfills for specific modules.
      overrides: {
        // Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
        fs: 'memfs',
      },
      // Whether to polyfill `node:` protocol imports.
      protocolImports: true,
    }),
  ],
})
```

### All polyfills

- If protocolImports is true, also adds node:[module]

```js
[
  '_stream_duplex',
  '_stream_passthrough',
  '_stream_readable',
  '_stream_transform',
  '_stream_writable',
  'assert',
  'buffer',
  'child_process',
  'cluster',
  'console',
  'constants',
  'crypto',
  'dgram',
  'dns',
  'domain',
  'events',
  'fs',
  'http',
  'http2',
  'https',
  'module',
  'net',
  'os',
  'path',
  'process',
  'punycode',
  'querystring',
  'readline',
  'repl',
  'stream',
  'string_decoder',
  'sys',
  'timers',
  'timers/promises',
  'tls',
  'tty',
  'url',
  'util',
  'vm',
  'zlib',
]
```

## About the author

Hello! My name is David, and in my spare time, I build tools to help developers be more productive. If you find my work valuable, I would really appreciate a [sponsorship](https://voracious.link/sponsor) or [donation](https://voracious.link/donate). If you want to see more of my work, check out [davidmyers.dev](https://davidmyers.dev).

Thanks for your support! 🪴

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