{"id":21259,"library":"esbuild-plugin-lodash","title":"esbuild-plugin-lodash","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/josteph/esbuild-plugin-lodash","tags":["javascript","esbuild","esbuild-plugin","lodash"],"install":[{"cmd":"npm install esbuild-plugin-lodash","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-lodash","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-lodash","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin is designed for esbuild's plugin system.","package":"esbuild","optional":true}],"imports":[{"note":"The plugin is exported as an ESM default export. For CJS, use default import or require('esbuild-plugin-lodash').default.","wrong":"const lodashTransformer = require('esbuild-plugin-lodash');","symbol":"default","correct":"import lodashTransformer from 'esbuild-plugin-lodash';"},{"note":"The package exports a single default function; named import will fail.","wrong":"import { lodashTransformer } from 'esbuild-plugin-lodash';","symbol":"lodashTransformer","correct":"import lodashTransformer from 'esbuild-plugin-lodash';"},{"note":"The plugin is a factory function, not a class. Call it as a function.","wrong":"new lodashTransformer()","symbol":"plugin function call","correct":"lodashTransformer()"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport lodashTransformer from 'esbuild-plugin-lodash';\n\nawait esbuild.build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    lodashTransformer({\n      filter: /.*/,\n      outLodashPackage: 'lodash-es'\n    }),\n  ],\n});","lang":"javascript","description":"Shows how to use the plugin in an esbuild build, including options for filter and output package."},"warnings":[{"fix":"Use named imports only, or manually rewrite to path-based imports.","message":"Plugin 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').","severity":"gotcha","affected_versions":"<=1.2.0"},{"fix":"Use direct imports per method, or avoid lodash chaining.","message":"Plugin does not rewrite calls to chained lodash methods (e.g., _.chain). Only top-level named imports are transformed.","severity":"gotcha","affected_versions":"<=1.2.0"},{"fix":"Import from 'lodash-es' instead and use esbuild's built-in tree-shaking.","message":"The 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.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure esbuild version matches peer dependency range (check package.json). For esbuild >=0.17, consider updating the plugin.","cause":"The plugin has a peer dependency on esbuild; incompatible versions may cause runtime errors.","error":"Error: The plugin \"esbuild-plugin-lodash\" is not compatible with esbuild version X.X.X"},{"fix":"Use require('esbuild-plugin-lodash').default or import the ESM version.","cause":"In CJS, require returns the module object, not the default export.","error":"TypeError: lodashTransformer is not a function"},{"fix":"Use lodash v4.x or set outLodashPackage to 'lodash-es'.","cause":"Lodash v5 changed its exports map, breaking the transformed import 'lodash/get'.","error":"Module not found: Package path ./get is not exported from package lodash (see exports field in ./node_modules/lodash/package.json)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}