bit-loader-builtins

raw JSON →
2.0.2 verified Sat Apr 25 auth: no javascript maintenance

A loader plugin for bit-bundler that resolves Node.js built-in modules (like 'fs', 'path', 'http') and provides browser-compatible shims using browserify's builtins. Version 2.0.2 is the latest stable release, though the project appears to be in maintenance mode with no recent updates. Key differentiator: it seamlessly integrates with bit-bundler to handle Node.js globals (__dirname, __filename) and built-in modules during browser bundling, leveraging browserify's established polyfills.

error Module not found: Can't resolve 'fs' in ...
cause bit-loader-builtins not registered with bit-bundler or not installed.
fix
Run 'npm install bit-loader-builtins' and add 'bundle.loader(builtins())' to your bit-bundler setup.
error TypeError: builtins is not a function
cause Incorrect import: using default import but wrong syntax or missing default export.
fix
Use 'import builtins from 'bit-loader-builtins'' (ESM) or 'const builtins = require('bit-loader-builtins').default' (CJS).
error Cannot resolve module 'path'
cause The builtins plugin is not applied or bit-bundler is not configured to use it.
fix
Double-check that bit-loader-builtins is installed and the loader is added to the bundle instance before bundling.
gotcha The package relies on browserify's builtins which may not cover all Node.js modules or may have incomplete polyfills.
fix Test bundling of target modules thoroughly; avoid relying on unsupported builtins like 'cluster' or 'child_process'.
deprecated bit-bundler itself is deprecated or no longer actively maintained, making this plugin of limited use.
fix Consider migrating to a modern bundler like Webpack, Rollup, or esbuild which have built-in Node.js polyfill support.
gotcha __dirname and __filename shimming may not work correctly in all scenarios if the module resolution is not properly set.
fix Ensure bit-bundler is configured to handle the 'builtins' loader plugin correctly. Verify the bundle output for expected values.
npm install bit-loader-builtins
yarn add bit-loader-builtins
pnpm add bit-loader-builtins

Creates a bit-bundler Bundle and registers the builtins plugin to handle Node.js built-ins and globals.

import builtins from 'bit-loader-builtins';
import { Bundle } from 'bit-bundler';

const bundle = new Bundle();
bundle.loader(builtins());
// Now bundle can resolve 'fs', 'path', etc. and replace __dirname/__filename