Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

A Vite plugin to polyfill native Node modules for the browser

License

Notifications You must be signed in to change notification settings

milahu/vite-plugin-node-polyfills

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-node-polyfills

A Vite plugin to polyfill native Node modules for the browser

Status

⚠️ Deprecated in favor of https://github.com/sodatea/vite-plugin-node-stdlib-browser

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(),
  ],
})

Why?

The following error can occur when a package references a native Node module without providing a polyfill. See this Vite issue for more info.

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

Attribution

Special thanks to @FbN for putting together this gist.

About

A Vite plugin to polyfill native Node modules for the browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • JavaScript 100.0%