Registry / serialization / babel-plugin-import-glob

babel-plugin-import-glob

JSON →
library2.0.0jsnpmunverified

Babel plugin that enables importing modules using glob patterns, allowing developers to import multiple modules from a directory in a single statement. Current stable version is 2.0.0, released with breaking changes: the glob: prefix is now optional, patterns must be relative (starting with ./ or ../), and identifiers are generated from the dynamic portions of the pattern. This plugin is tested with Node.js 4+. It supports default member import, namespace import, side-effect import, and member aliasing, but does not support importing the default export. The underlying mechanism uses the 'glob' package for pattern matching and 'identifierfy' for converting match strings to valid JavaScript identifiers. Key differentiators: avoids manual per-module imports, useful for template directories or side-effect modules, but not recommended for general use due to potential maintainability issues.

npm install babel-plugin-import-glob
INSTALL
IMPORT
SIG · BABEL-PLUGIN-IMPOR
B
babel-plugin-import-glob
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
Not supported; use named imports or namespace import.
import myModule from './path/**/*.js'
This plugin does not support default imports from glob patterns; attempting so throws a SyntaxError.
named
import { main } from './templates/**/*.handlebars.js'
import { doesNotExist } from './templates/**/*.handlebars.js'
Named imports must correspond to actual matched files. Using the glob: prefix is optional since v2.0.0.
namespace
import * as templates from './templates/**/*.handlebars.js'
import * as templates from 'glob:./templates/**/*.handlebars.js' (prefix is optional)
Namespace import collects all default exports of matched modules into an object.

Shows Babel plugin configuration and three import styles: named with alias, namespace, and side-effect import using glob patterns.

// .babelrc { "plugins": ["import-glob"] } // index.js // Assuming files: templates/main.handlebars.js and templates/_partial.handlebars.js import { main, _partial as partial } from './templates/**/*.handlebars.js'; import * as all from './templates/**/*.handlebars.js'; import './side-effects/*.js'; // Side-effect import console.log(main); // exports from templates/main.handlebars.js console.log(partial); // aliased from _partial console.log(all.main); // via namespace
Debug
Known issues
breakingPatterns must be relative (start with ./ or ../) since v2.0.0. Absolute paths or bare names will throw SyntaxError.
fix
Prefix glob patterns with ./ or ../
affects: >=2.0.0
breakingIdentifiers are now derived from dynamic portions of the pattern only, not from common path segments or extensions. v1.x behavior differs.
fix
Review import member names generated from patterns; they may have changed from v1.
affects: >=2.0.0
gotchaCannot import default export from glob pattern. Attempting to do so throws SyntaxError.
fix
Use named import or namespace import instead.
affects: >=0.0.0
gotchaImporting a member name that does not correspond to any matched file throws SyntaxError.
fix
Ensure all imported members exist as filenames generating the expected identifiers.
affects: >=0.0.0
gotchaIdentifier collision from multiple matches (e.g., two files generating same name) throws SyntaxError.
fix
Adjust filenames to avoid identical dynamic portions after identifier conversion.
affects: >=2.0.0
gotchaThe glob: prefix is optional in v2.0.0, but if used with wrong casing (e.g., Glob:) causes issues.
fix
Use exactly 'glob:' (lowercase) or omit it.
affects: >=2.0.0
deprecatedNode.js <4 is not supported as of v2.0.0. Plugin may fail on older runtimes.
fix
Upgrade Node.js to version 4 or later.
affects: >=2.0.0
Errors
Common errors & fixes
SyntaxError: import from 'pattern' must start with './' or '../'
Glob pattern does not start with ./ or ../ as required since v2.0.0.
fix
Change pattern to start with ./ or ../, e.g., './modules/**/*.js'
SyntaxError: ... is not a valid identifier
The pattern generated a match string that could not be converted to a valid JavaScript identifier (e.g., starting with digit).
fix
Rename matched files to ensure dynamic portions produce valid identifiers.
SyntaxError: Cannot import default from a glob pattern
Using default import (import X from '...') with a glob pattern, which is not supported.
fix
Use named import (import { ... } from '...') or namespace import (import * as X from '...').
SyntaxError: No matches found for pattern
The glob pattern does not match any files in the filesystem.
fix
Verify the pattern syntax and that expected files exist relative to the importing file.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
globrequiredUsed for resolving glob patterns to file paths during transpilation.
identifierfyrequiredConverts file path fragments to valid JavaScript identifiers for import member names.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-import-glob — npm install babel-plugin-import-glob · libregistry