@bangjelkoski/vite-plugin-node-polyfills
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments. Supports node: protocol 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, packages that use them must be polyfilled to function in browser environments. In an attempt to prevent runtime errors, Vite produces errors or warnings when your code references builtin modules such as fs or path.

Getting Started

Install the package as a dev dependency.

# 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.

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    nodePolyfills({
      // Whether to polyfill `node:` protocol imports.
      protocolImports: true,
    }),
  ],
})

Package Sidebar

Install

npm i @bangjelkoski/vite-plugin-node-polyfills

Weekly Downloads

95

Version

0.0.2

License

MIT

Unpacked Size

20.2 kB

Total Files

8

Last publish

Collaborators

  • bangjelkoski