Registry / devops / import-glob

import-glob

JSON →
library1.5.0jsnpmunverified

Webpack preloader that expands glob patterns in ES6 import statements and Sass @import rules. Version 1.5.0 (latest) is stable; no recent updates. Replaces literal imports with individual file imports. Works only as a Webpack loader (preloader or chained). Alternatives include `bulk-require` or `import-meta-glob` for ESM. No TypeScript support. Not compatible with webpack 2+ as a preloader (must use chained loader). Last published in 2015.

npm install import-glob
INSTALL
IMPORT
SIG · IMPORT-GLOB
I
import-glob
devopsjavascriptv1.5.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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

import-glob
// As a webpack loader in config: { test: /\.js$/, loader: 'import-glob' }
import importGlob from 'import-glob'; // Not meant to be used as a library import
This is a Webpack loader, not a JavaScript module to import. Use in webpack config only.

Basic webpack config using import-glob as a loader and code that it transforms.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, use: 'import-glob' }, { test: /\.scss$/, use: 'import-glob' } ] } }; // In your JS code: import modules from './foo/**/*.js'; // After processing, becomes: // import * as module0 from './foo/1.js'; // import * as module1 from './foo/bar/2.js'; // import * as module2 from './foo/bar/3.js'; // modules = [module0, module1, module2] // For side effects: import './foo/**/*.scss';
Debug
Known issues
breakingwebpack 2+ dropped support for preloaders; import-glob must be configured as a chained loader or normal rule, not in preLoaders.
fix
Use module.rules instead of module.preLoaders.
affects: >=1.0.0
gotchaGlob patterns in import statements are not standard JavaScript; code will not work without the loader. Bypassing the loader causes syntax errors.
fix
Always ensure the loader is applied to files containing glob imports.
affects: >=0.0.0
deprecatedPackage has not been updated since 2015. Consider using native dynamic imports or import.meta.glob (Vite) for modern projects.
fix
Use Vite's import.meta.glob or Webpack 5's magic comments with context modules.
affects: >=1.0.0
Errors
Common errors & fixes
Module build failed: Error: 'import-glob' is not compatible with webpack 2+ as a preloader. Please use the loader in the rules section.
Webpack 2+ removed preLoaders; import-glob requires preloader behavior.
fix
Move loader configuration from `module.preLoaders` to `module.rules` and ensure order if needed.
SyntaxError: Unexpected token *
Glob pattern in import statement is not transpiled without the import-glob loader.
fix
Ensure webpack config has the correct test and loader for files using glob imports.
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
webpackrequiredDesigned as a Webpack loader; requires Webpack to function.
globrequiredUsed for glob pattern matching.
Agent activity
9 hits · last 30 days
node
8
Resources
import-glob — npm install import-glob · libregistry