package
Node standard library for browser.
npm install node-stdlib-browserGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Node standard library for browser.
Features:
node-libs-browser
for Webpacknode: protocol which
allows for builtin modules to be referenced by valid absolute URL stringsCheck example to see how modules work in browser environment.
npm install node-stdlib-browser --save-devAs of Webpack 5, aliases and globals provider need to be explicitly configured.
If you want to handle node: protocol imports, you
need to provide helper plugin.
// webpack.config.js
const stdLibBrowser = require('node-stdlib-browser');
const {
NodeProtocolUrlPlugin
} = require('node-stdlib-browser/helpers/webpack/plugin');
const webpack = require('webpack');
module.exports = {
// ...
resolve: {
alias: stdLibBrowser
},
plugins: [
Since many packages expose only CommonJS implementation, you need to apply plugins to handle CommonJS exports. Those packages could have dependencies installed with npm so they need to be properly resolved (taking into account browser-specific implementations).
Some dependencies can have circular dependencies and Rollup will warn you about that. You can ignore these warnings with helper function (reference).
// rollup.config.js
const stdLibBrowser = require('node-stdlib-browser');
const {
handleCircularDependancyWarning
} = require('node-stdlib-browser/helpers/rollup/plugin');
const { default: resolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
Vite config uses combination of Rollup and esbuild plugins. It’s important to use dynamic import when using CommonJS configuration so ESM version of modules is picked up. This allows Vite bundling to use our mocking implementation and implement heuristics such as proper tree-shaking and dead code removal marking.
const inject = require('@rollup/plugin-inject');
const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
module.exports = async () => {
const { default: stdLibBrowser } = await import('node-stdlib-browser');
return {
resolve: {
alias: stdLibBrowser
},
optimizeDeps: {
include: ['buffer', 'process']
},
plugins: [
Using esbuild requires you to use helper utilities and plugins.
const path = require('path');
const esbuild = require('esbuild');
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');
(async () => {
await esbuild.build({
// ...
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer'
Bundling ES modules is currently not supported natively in Browserify, but you can try using esmify or babelify for transforming to CommonJS first.
const fs = require('fs');
const path = require('path');
const browserify = require('browserify');
const aliasify = require('aliasify');
const stdLibBrowser =
Returns: object
Exports absolute paths to each module directory (where package.json is
located), keyed by module names. Modules without browser replacements return
module with default export null.
Some modules have mocks in the mock directory. These are replacements with minimal functionality.
fsfs package doesn’t return anything since there are many different ways you can
implement file system functionality in browser.
Examples of implementations:
Minimum supported version should be Node 10.
If you’re using ESM in Node < 12.20, note that subpath patterns are not supported so mocks can’t be handled. In that case, it’s recommended to use CommonJS implementation.
Minimum supported version should be Internet Explorer 11, but most modules support even Internet Explorer 9.
You can use default @types/node types.
MIT © Ivan Nikolić
If you’re using ESM config, additional configuration is needed to handle unspecified extensions:
// webpack.config.js
module.exports = {
// ...
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
}
]
}
};If you wish to use simpler configuration, you can use one of the available Vite plugins which use this package under the hood:
buffer@5 for IE 11 support |
child_process |
cluster |
console | console-browserify | console |
constants | constants-browserify |
crypto | crypto-browserify |
dgram |
dns | dns |
domain | domain-browser |
events | events |
fs | Mocking fs |
http | stream-http |
https | https-browserify |
module |
net | net |
os | os-browserify |
path | path-browserify |
process | process | process | Contains additional exports from newer Node |
punycode | punycode | punycode@1 for browser support |
querystring | querystring-es3 | Contains additional exports from newer Node versions |
readline |
repl |
stream | stream-browserify |
string_decoder | string_decoder |
sys | util |
timers | timers-browserify |
timers/promises | isomorphic-timers-promises |
tls | tls |
tty | tty-browserify | tty |
url | node-url | Contains additional exports from newer Node versions (URL and URLSearchParams are not polyfilled) |
util | util |
vm | vm-browserify |
zlib | browserify-zlib |
_stream_duplex | readable-stream |
_stream_passthrough | readable-stream |
_stream_readable | readable-stream |
_stream_transform | readable-stream |
_stream_writable | readable-stream |
Estimated unpacked size across 64 packages.
4.9 MB+
Includes dependencies.
^3.2.0
3.2.0
^0.3.0
0.3.0
^1.0.1
1.1.2
^1.1.1
1.1.1
4.22.0
5.7.0
^1.0.0
1.3.0
0.0.1
0.0.1
^2.0.0
2.0.0
^0.2.0
0.2.0
^1.0.1
1.0.1
^0.2.1
0.2.1
^3.6.0
4.8.0
^1.0.0
1.0.0
^3.12.1
3.12.1
^3.0.0
3.0.0
^2.0.4
2.0.12
^1.1.0
1.2.0
^1.0.0
1.0.0
1.0.1