# node-polyfill-webpack-plugin

> Polyfill Node.js core modules in Webpack.

Latest version **4.1.0** (published 2024-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-polyfill-webpack-plugin
pnpm add node-polyfill-webpack-plugin
yarn add node-polyfill-webpack-plugin
bun add node-polyfill-webpack-plugin
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2024-12-04 |
| First published | 2020-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 302 |
| Author | Richie Bendall |
| Maintainers | richienb |
| Keywords | webpack, webpack-plugin, node, polyfill |

## Links

- npm: https://www.npmjs.com/package/node-polyfill-webpack-plugin
- Repository: https://github.com/Richienb/node-polyfill-webpack-plugin
- Homepage: https://github.com/Richienb/node-polyfill-webpack-plugin#readme
- Issues: https://github.com/Richienb/node-polyfill-webpack-plugin/issues
- npm.io page: https://npm.io/package/node-polyfill-webpack-plugin

## Dependencies (2)

- [type-fest](https://npm.io/package/type-fest.md) ^4.27.0
- [node-stdlib-browser](https://npm.io/package/node-stdlib-browser.md) ^1.3.0

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

- 4.1.0 (latest) — 2024-12-04
- 4.0.0 — 2024-05-24
- 3.0.0 — 2023-12-06
- 2.0.1 — 2022-07-30
- 2.0.0 — 2022-06-24
- 1.1.4 — 2021-06-30
- 1.1.3 — 2021-06-15
- 1.1.2 — 2021-05-12
- 1.1.1 — 2021-05-05
- 1.1.0 — 2021-03-28
- 1.0.3 — 2021-02-24
- 1.0.2 — 2021-01-04
- 1.0.1 — 2021-01-04
- 1.0.0 — 2020-10-13

## README

# node-polyfill-webpack-plugin

Polyfill Node.js core modules in Webpack.

This module is only needed for [Webpack 5+](https://github.com/webpack/changelog-v5#automatic-nodejs-polyfills-removed).

## Install

```sh
npm install node-polyfill-webpack-plugin
```

## Usage

Add the following to your `webpack.config.js`:

```js
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin(),
	],
};
```

`console`, `process`, and most deprecated/internal Node.js core modules are not polyfilled by default. If you still need to polyfill them, you can use the `additionalAliases` option:

```js
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin({
			additionalAliases: ['process', 'punycode'],
		}),
	],
};
```

The `fs` module resolves to nothing because its functionality cannot replicated in the browser.

## API

### new NodePolyfillPlugin(options?)

#### options

Type: `object`

`onlyAliases` is mutually exclusive with `excludeAliases` and `additionalAliases`.

#### excludeAliases

If you don't want a module to be polyfilled, you can specify aliases to be skipped here.

```js
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin({
			excludeAliases: ['console'],
		}),
	],
};
```

#### additionalAliases

Alternatively, you can choose to add certain aliases to the list of polyfilled modules. For example, you can choose to polyfill `console`.

```js
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin({
			additionalAliases: ['console'],
		}),
	],
};
```

#### onlyAliases

You can also choose to only include certain aliases, ignoring the defaults. For example, you can have only `console` polyfilled.

```js
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
	// Other rules...
	plugins: [
		new NodePolyfillPlugin({
			onlyAliases: ['console'],
		}),
	],
};
```

## Aliases

### Globals

- `Buffer`
- `console`
- `process`

### Modules

- `assert`
- `buffer`
- `console`
- `constants`
- `crypto`
- `domain`
- `events`
- `http`
- `https`
- `os`
- `path`
- `punycode`
- `process`
- `querystring`
- `stream`
- `_stream_duplex`
- `_stream_passthrough`
- `_stream_readable`
- `_stream_transform`
- `_stream_writable`
- `string_decoder`
- `sys`
- `timers`
- `tty`
- `url`
- `util`
- `vm`
- `zlib`

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