esbuild-plugin-glob-import
raw JSON → 0.2.0 verified Fri May 01 auth: no javascript
An esbuild plugin (v0.2.0, stable but low activity) that enables glob patterns in import statements to bundle multiple files as a single module. Differentiates from alternatives like esbuild-plugin-import-glob by supporting `entryPoint` and `camelCase` options for organizing imports into nested objects keyed by directory structure. Built on fast-glob for performance.
Common errors
error Error: Cannot find module 'fast-glob' ↓
cause fast-glob is a required runtime dependency but not automatically installed.
fix
Run
npm install fast-glob in your project. error ERROR: The plugin 'esbuild-plugin-glob-import' is not a valid esbuild plugin. It must return an object with a name and setup method. ↓
cause Using an incorrect import (e.g., named export instead of default).
fix
Use
import globImport from 'esbuild-plugin-glob-import' (no named import). error error TS2307: Cannot find module './pages/**/index.js' or its corresponding type declarations. ↓
cause TypeScript cannot resolve glob import syntax; it's not a real module.
fix
Create a type declaration file (e.g., glob.d.ts) with
declare module '*?glob' or suppress with // @ts-ignore. error TypeError: opts.entryPointMatch is not a function ↓
cause Passing entryPointMatch option as something other than a function or null.
fix
Ensure entryPointMatch is either null or a function.
Warnings
gotcha Glob patterns in import statements are not valid JavaScript; they are resolved at build time and replaced with generated module code. Tooling like TypeScript or ESLint will report errors on the raw import. ↓
fix Add a declaration file (e.g., glob.d.ts) with `declare module '*?glob'` or use `// @ts-ignore` comments.
breaking Prior to v0.2.0, the plugin required explicit `opts.entryPoint` to be set; default behavior changed to `entryPoint: 'index.js'`. ↓
fix Upgrade to v0.2.0 and review default options; if relying on falsey entryPoint, set `entryPoint: false` explicitly.
gotcha The plugin uses fast-glob under the hood, but that dependency is not listed in package.json peerDependencies. If fast-glob is not installed or version mismatch occurs, builds may fail silently. ↓
fix Ensure fast-glob is installed (npm install fast-glob) and at a compatible version.
gotcha The `camelCase` option transforms filenames and directory names using lodash.camelCase, which can produce unexpected results for non-standard naming conventions (e.g., 'my-file.js' becomes 'myFile'). ↓
fix Set `camelCase: false` to preserve original names, or rename source files accordingly.
Install
npm install esbuild-plugin-glob-import yarn add esbuild-plugin-glob-import pnpm add esbuild-plugin-glob-import Imports
- default (globImport) wrong
const globImport = require('esbuild-plugin-glob-import')correctimport globImport from 'esbuild-plugin-glob-import' - type GlobImportOptions wrong
import { GlobImportOptions } from 'esbuild-plugin-glob-import'correctimport type { GlobImportOptions } from 'esbuild-plugin-glob-import' - esbuild plugin usage wrong
import { globImport } from 'esbuild-plugin-glob-import'correctimport globImport from 'esbuild-plugin-glob-import'; esbuild.build({ plugins: [globImport({ camelCase: true })] })
Quickstart
import esbuild from 'esbuild';
import globImport from 'esbuild-plugin-glob-import';
await esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [
globImport({
camelCase: true,
entryPoint: 'index.js'
})
]
});
// Now in any file you can do:
import pages from './pages/**/index.js';
console.log(pages); // { home: {...}, about: {...}, error: {...} }