Registry / web-framework / esbuild-plugin-lodash

esbuild-plugin-lodash

JSON →
library1.2.0jsnpmunverified

An esbuild plugin (v1.2.0) that rewrites named imports from 'lodash' to direct module imports like 'lodash/get' to enable tree-shaking. Released on npm, with active maintenance. Similar to babel-plugin-lodash but for esbuild, offering a filter option and support for custom output package (e.g., lodash-es). Distinct from alternatives like manual import optimization or using lodash-es directly. Works with both CJS and ESM, handles quotes, and fixes edge cases like 'lodash/last' imports.

npm install esbuild-plugin-lodash
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-LOD
E
esbuild-plugin-lodash
web-frameworkjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import lodashTransformer from 'esbuild-plugin-lodash';
const lodashTransformer = require('esbuild-plugin-lodash');
The plugin is exported as an ESM default export. For CJS, use default import or require('esbuild-plugin-lodash').default.
lodashTransformer
import lodashTransformer from 'esbuild-plugin-lodash';
import { lodashTransformer } from 'esbuild-plugin-lodash';
The package exports a single default function; named import will fail.
plugin function call
lodashTransformer()
new lodashTransformer()
The plugin is a factory function, not a class. Call it as a function.

Shows how to use the plugin in an esbuild build, including options for filter and output package.

import esbuild from 'esbuild'; import lodashTransformer from 'esbuild-plugin-lodash'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [ lodashTransformer({ filter: /.*/, outLodashPackage: 'lodash-es' }), ], });
Debug
Known issues
gotchaPlugin only works with direct named imports like import { get } from 'lodash'. It does not handle wildcard imports (import * as _ from 'lodash') or default imports (import _ from 'lodash').
fix
Use named imports only, or manually rewrite to path-based imports.
affects: <=1.2.0
gotchaPlugin does not rewrite calls to chained lodash methods (e.g., _.chain). Only top-level named imports are transformed.
fix
Use direct imports per method, or avoid lodash chaining.
affects: <=1.2.0
deprecatedThe npm package is named 'esbuild-plugin-lodash', but the most popular lodash tree-shaking plugin for esbuild is now 'esbuild-plugin-lodash-es' or manual tree-shaking. Consider using lodash-es directly instead.
fix
Import from 'lodash-es' instead and use esbuild's built-in tree-shaking.
affects: all
Errors
Common errors & fixes
Error: The plugin "esbuild-plugin-lodash" is not compatible with esbuild version X.X.X
The plugin has a peer dependency on esbuild; incompatible versions may cause runtime errors.
fix
Ensure esbuild version matches peer dependency range (check package.json). For esbuild >=0.17, consider updating the plugin.
TypeError: lodashTransformer is not a function
In CJS, require returns the module object, not the default export.
fix
Use require('esbuild-plugin-lodash').default or import the ESM version.
Module not found: Package path ./get is not exported from package lodash (see exports field in ./node_modules/lodash/package.json)
Lodash v5 changed its exports map, breaking the transformed import 'lodash/get'.
fix
Use lodash v4.x or set outLodashPackage to 'lodash-es'.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
esbuildoptionalPeer dependency; plugin is designed for esbuild's plugin system.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
esbuild-plugin-lodash — npm install esbuild-plugin-lodash · libregistry