rollup-plugin-esbuild-resolve

raw JSON →
1.3.1 verified Mon Apr 27 auth: no javascript

A Rollup plugin that replaces @rollup/plugin-node-resolve and TypeScript paths resolution plugins with esbuild's own resolution algorithm. Version 1.3.1 is current and stable, with infrequent releases. It reads the closest tsconfig.json from each importer, enabling correct resolution across multiple interconnected projects with their own tsconfig files. Supports all esbuild resolution options (platform, conditions, mainFields, etc.) and works alongside other resolve plugins. Ships TypeScript types.

error Error: Cannot find module 'esbuild'
cause Missing peer dependency esbuild.
fix
Run npm install esbuild --save-dev or yarn add esbuild --dev.
error TypeError: esbuildResolve is not a function
cause Using default import instead of named import (or vice versa with CJS).
fix
Use import { esbuildResolve } from 'rollup-plugin-esbuild-resolve' (ESM) or const { esbuildResolve } = require('rollup-plugin-esbuild-resolve') (CJS).
error The plugin 'esbuildResolve' is not compatible with rollup v2.79.1 - expected a function-like plugin
cause Using an older version of the plugin that does not support Rollup v2.79.1+ properly (pre-v1.3).
fix
Update rollup-plugin-esbuild-resolve to v1.3.0 or later.
error Error: esbuild's resolve API returned an error: "Could not resolve "some-module"
cause The plugin cannot resolve a module, likely due to incorrect esbuild options (e.g., wrong platform, missing conditions) or missing dependency.
fix
Check esbuild options passed to the plugin (platform, resolveExtensions, conditions). Ensure the module is installed. Optionally fallback to @rollup/plugin-node-resolve.
breaking When upgrading from v1.0 to v1.1, the plugin switched to named export `esbuildResolve` instead of default export. Old code using `import esbuildResolve from 'rollup-plugin-esbuild-resolve'` will break.
fix Change import to `import { esbuildResolve } from 'rollup-plugin-esbuild-resolve'`.
deprecated Options passed directly to plugin (e.g., `esbuildResolve({ platform: 'node' })`) are deprecated since v1.2.0. Use nested `esbuild` option.
fix Wrap esbuild-specific options in `esbuild` object: `esbuildResolve({ esbuild: { platform: 'node' } })`.
gotcha The plugin reads the closest `tsconfig.json` from each importer file, not from the project root. This may produce different resolution results compared to TypeScript's default behavior which reads the root `tsconfig.json`. Works as intended for monorepos, but can surprise users expecting single root tsconfig behavior.
fix Explicitly set the `tsconfig` option to a specific file path if you need consistent single tsconfig behavior: `esbuildResolve({ esbuild: { tsconfig: './tsconfig.json' } })`.
gotcha The plugin requires both `esbuild` and `rollup` as peer dependencies. Using an incompatible version of either (e.g., esbuild <0.19.10 or rollup <2.79.1) will cause errors or undefined behavior.
fix Ensure `esbuild` version ^0.19.10 and `rollup` version ^2.79.1 || ^3.0.0 || ^4.0.0 are installed.
breaking Support for Rollup v2 older than 2.79.1 was dropped in v1.3.0. Rollup v2.79.1 is now the minimum.
fix Upgrade Rollup to v2.79.1 or later, or use v3/v4.
npm install rollup-plugin-esbuild-resolve
yarn add rollup-plugin-esbuild-resolve
pnpm add rollup-plugin-esbuild-resolve

Minimal Rollup config using esbuildResolve plugin with custom esbuild options for node platform and extended resolve extensions.

// rollup.config.js
import { esbuildResolve } from 'rollup-plugin-esbuild-resolve';

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'esm',
  },
  plugins: [
    esbuildResolve({
      esbuild: {
        platform: 'node',
        resolveExtensions: ['.mjs', '.js', '.ts', '.json'],
      },
    }),
  ],
};