glob-import-esbuild-plugin
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
An esbuild plugin (v1.0.0) that enables importing multiple modules using a glob pattern, returning an object mapping file paths to their module exports (including named exports). The result is inspired by Vite's glob import but is not identical. It's stable but not actively maintained (latest release 2020). Unlike alternatives (e.g., esbuild-plugin-import-glob which returns an array and discards named exports), this plugin preserves both default and named exports.
Common errors
error Error: generateGlobImports is not a function ↓
cause Incorrect import method – using require instead of import.
fix
Use ESM import: import globImportPlugin from 'glob-import-esbuild-plugin'.
error TypeError: globImportPlugin is not a function ↓
cause The plugin must be called as a function (returns a plugin object).
fix
Pass globImportPlugin() (with parentheses) in the plugins array.
error Error: [plugin: glob-import-esbuild-plugin] No matching files found for pattern ↓
cause Glob pattern didn't match any files, possibly due to wrong relative path.
fix
Double-check the glob pattern path relative to the file using it.
Warnings
gotcha The plugin returns absolute file paths as keys in the module object, not relative paths. ↓
fix Either process paths to be relative if needed, or be aware of absolute paths in your code.
gotcha Glob patterns are resolved relative to the file containing the import statement, not the project root. ↓
fix Ensure glob patterns are relative to the importing file's location.
gotcha The plugin does not support dynamic imports; glob patterns must be static strings. ↓
fix Use literal strings for glob patterns, not variables or expressions.
Install
npm install glob-import-esbuild-plugin yarn add glob-import-esbuild-plugin pnpm add glob-import-esbuild-plugin Imports
- default wrong
const globImportPlugin = require('glob-import-esbuild-plugin')correctimport globImportPlugin from 'glob-import-esbuild-plugin' - globImportPlugin
import globImportPlugin from 'glob-import-esbuild-plugin' - GlobImportPlugin wrong
// No named export GlobImportPlugin existscorrectimport globImportPlugin from 'glob-import-esbuild-plugin'
Quickstart
import { build } from 'esbuild';
import globImportPlugin from 'glob-import-esbuild-plugin';
await build({
entryPoints: ['src/index.js'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [globImportPlugin()]
});