Registry / devops / glob-import-esbuild-plugin

glob-import-esbuild-plugin

JSON →
library1.0.0jsnpmunverified

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.

npm install glob-import-esbuild-plugin
INSTALL
IMPORT
SIG · GLOB-IMPORT-ESBUIL
G
glob-import-esbuild-plugin
devopsjavascriptv1.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.

default
import globImportPlugin from 'glob-import-esbuild-plugin'
const globImportPlugin = require('glob-import-esbuild-plugin')
Package is ESM-only; CommonJS require will fail in Node >=10.16 but esbuild handles it.
globImportPlugin
import globImportPlugin from 'glob-import-esbuild-plugin'
Default export used as a plugin for esbuild.
GlobImportPlugin
import globImportPlugin from 'glob-import-esbuild-plugin'
// No named export GlobImportPlugin exists
Only default export is available.

Shows how to configure esbuild with the glob import plugin to bundle code that uses glob imports.

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()] });
Debug
Known issues
gotchaThe 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.
affects: >=1.0.0
gotchaGlob 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.
affects: >=1.0.0
gotchaThe plugin does not support dynamic imports; glob patterns must be static strings.
fix
Use literal strings for glob patterns, not variables or expressions.
affects: >=1.0.0
Errors
Common errors & fixes
Error: generateGlobImports is not a function
Incorrect import method – using require instead of import.
fix
Use ESM import: import globImportPlugin from 'glob-import-esbuild-plugin'.
TypeError: globImportPlugin is not a function
The plugin must be called as a function (returns a plugin object).
fix
Pass globImportPlugin() (with parentheses) in the plugins array.
Error: [plugin: glob-import-esbuild-plugin] No matching files found for pattern
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.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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