Registry / devops / esbuild-plugin-resolve

esbuild-plugin-resolve

JSON →
library2.0.0jsnpmunverified

An esbuild plugin (v2.0.0, last updated 2023) that allows you to replace module import paths during bundling. It intercepts resolve calls and swaps dependencies, useful for mocking or aliasing in tests or builds. Differentiators: lightweight, no dependencies, regex-based matching. Released as v1.0.0 in 2022, with v2.0.0 switching to ES modules. Maintenance-mode with no recent commits.

npm install esbuild-plugin-resolve
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-RES
E
esbuild-plugin-resolve
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

resolve
import resolve from 'esbuild-plugin-resolve'
const resolve = require('esbuild-plugin-resolve')
Default export; v2.0.0 is ESM-only, require() fails.
resolve
import * as pkg from 'esbuild-plugin-resolve'; const resolve = pkg.default
import { resolve } from 'esbuild-plugin-resolve'
It is a default export, not a named export. Named import will be undefined.
resolve (as plugin function)
plugins: [resolve({ test: 'foo' })]
plugins: [resolve({ test: 'foo' })]
Usage is straightforward; no wrong pattern beyond the import. The resolve function returns an esbuild plugin object.

Shows how to bundle with esbuild and replace 'lodash' imports with 'lodash-es' using the plugin.

import esbuild from 'esbuild'; import resolve from 'esbuild-plugin-resolve'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [resolve({ test: 'lodash', replaceWith: 'lodash-es' })] });
Debug
Known issues
breakingv2.0.0 switched to ES modules; CommonJS require() no longer works.
fix
Use ESM imports (import resolve from ...) or downgrade to v1.x.
affects: >=2.0.0
deprecatedThe 'replaceWith' option is not documented in v2.0.0; the API changed from v1.x to v2.0.0.
fix
Check plugin API: in v2.0.0, options might be different. Refer to the repository's usage examples.
affects: >=2.0.0
gotchaThe 'test' option is treated as a regex pattern without escaping; special regex characters can cause unexpected matches.
fix
Escape regex-special characters in the module name, e.g., use 'lodash\.merge' instead of 'lodash.merge'.
affects: >=1.0.0
gotchaIf the original module has no default export, the plugin may not resolve correctly (fixed in v1.1.0 but verify).
fix
Upgrade to v1.1.0 or later.
affects: <1.1.0
Errors
Common errors & fixes
Cannot find module 'esbuild-plugin-resolve'
Package not installed or incorrect import path.
fix
Run 'npm install --save-dev esbuild-plugin-resolve' and use valid import syntax for your module system.
TypeError: resolve is not a function
Named import instead of default import (ESM).
fix
Use 'import resolve from "esbuild-plugin-resolve"' instead of 'import { resolve } from "esbuild-plugin-resolve"'.
Error: The plugin must be an object with a name and setup function
The resolve function was not called; plugin array received the raw import.
fix
Call resolve() with options: plugins: [resolve({ test: 'foo' })].
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-resolve — npm install esbuild-plugin-resolve · libregistry