evanw/esbuild · error · Error
Module not found in bundle
Error message
Module not found in bundle: ${path} What it means
esbuild emits a generated runtime helper named __glob (internal/runtime/runtime.go:135) to power its glob-import feature, where a relative import specifier containing '*' is expanded at build time into a map of path -> loader-function. At runtime the generated code looks up the requested path in that map; if the key is absent it throws this error. In other words, the application asked the bundle for a module path that esbuild never statically matched when expanding the glob.
Solutions
- Rebuild so the glob is re-expanded and the new files appear in the map.
- Ensure the lookup key exactly matches the path string esbuild generated (same relative prefix like './', same file extension).
- If the key is dynamic/untrusted, guard it: only invoke the loader when the key actually exists in the map.
- Check the glob pattern in the import specifier actually covers the file you intend to load.
Example fix
// before
const mods = import.meta.glob('./pages/*.js')
const mod = mods[userPath]() // throws if userPath not in map
// after
const mods = import.meta.glob('./pages/*.js')
const loader = mods[userPath]
if (loader) {
const mod = loader()
} else {
// handle missing module
} Defensive patterns
Strategy: validation
Validate before calling
// Before indexing a glob-import map, confirm the key exists.
const mods = import.meta.glob('./pages/*.js')
const key = someUserPath
if (Object.prototype.hasOwnProperty.call(mods, key)) {
const mod = mods[key]()
} else {
throw new Error(`Unknown module path: ${key}`)
} Type guard
// Narrow a glob map entry to a callable loader.
const isGlobLoader = (v: unknown): v is () => unknown =>
typeof v === 'function'
const loader = mods[key]
if (isGlobLoader(loader)) loader()
else throw new Error(`No glob entry for ${key}`) Prevention
- Treat glob lookup keys as untrusted input and validate membership before invoking.
- Keep the import specifier glob pattern in sync with the files you intend to load.
- Rebuild whenever files under a glob directory are added, renamed, or deleted.
- Normalize requested paths (extension, './' prefix, slashes) to match the keys esbuild generates.
When it happens
Trigger: Code accesses a glob-import map (produced from a specifier like './pages/*.js') with a path string that was not present on disk at build time, has the wrong prefix/extension, or was constructed dynamically in a way that doesn't exactly match a bundled entry.
Common situations: New files added after the last build (map is stale); user input or a computed variable used as the lookup key; case-sensitivity or trailing-slash differences between the requested path and the matched path; Windows backslash vs forward-slash mismatches.
Related errors
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/2a05a87b3767e413.
Report an issue: GitHub.
Appendix: source
Thrown at internal/runtime/runtime.go:138
// shim to fall back to "globalThis.require" even if it's defined later
// (including property accesses such as "require.resolve") so we need to
// use a proxy (issue #1614).
export var __require =
/* @__PURE__ */ (x =>
typeof require !== 'undefined' ? require :
typeof Proxy !== 'undefined' ? new Proxy(x, {
get: (a, b) => (typeof require !== 'undefined' ? require : a)[b]
}) : x
)(function(x) {
if (typeof require !== 'undefined') return require.apply(this, arguments)
throw Error('Dynamic require of "' + x + '" is not supported')
})
// This is used for glob imports
export var __glob = map => path => {
var fn = map[path]
if (fn) return fn()
throw new Error('Module not found in bundle: ' + path)
}
// For object rest patterns
export var __restKey = key => typeof key === 'symbol' ? key : key + ''
export var __objRest = (source, exclude) => {
var target = {}
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop]
if (source != null && __getOwnPropSymbols)
`
// Avoid "of" when not using ES6
if !unsupportedJSFeatures.Has(compat.ForOf) {
text += `
for (var prop of __getOwnPropSymbols(source)) {
`
} else {View on GitHub (pinned to f6058f8364)