{"id":"2a05a87b3767e413","repo":"evanw/esbuild","slug":"module-not-found-in-bundle-path","errorCode":null,"errorMessage":"Module not found in bundle: ${path}","messagePattern":"Module not found in bundle: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/runtime/runtime.go","lineNumber":138,"sourceCode":"\t\t// shim to fall back to \"globalThis.require\" even if it's defined later\n\t\t// (including property accesses such as \"require.resolve\") so we need to\n\t\t// use a proxy (issue #1614).\n\t\texport var __require =\n\t\t\t/* @__PURE__ */ (x =>\n\t\t\t\ttypeof require !== 'undefined' ? require :\n\t\t\t\ttypeof Proxy !== 'undefined' ? new Proxy(x, {\n\t\t\t\t\tget: (a, b) => (typeof require !== 'undefined' ? require : a)[b]\n\t\t\t\t}) : x\n\t\t\t)(function(x) {\n\t\t\t\tif (typeof require !== 'undefined') return require.apply(this, arguments)\n\t\t\t\tthrow Error('Dynamic require of \"' + x + '\" is not supported')\n\t\t\t})\n\n\t\t// This is used for glob imports\n\t\texport var __glob = map => path => {\n\t\t\tvar fn = map[path]\n\t\t\tif (fn) return fn()\n\t\t\tthrow new Error('Module not found in bundle: ' + path)\n\t\t}\n\n\t\t// For object rest patterns\n\t\texport var __restKey = key => typeof key === 'symbol' ? key : key + ''\n\t\texport var __objRest = (source, exclude) => {\n\t\t\tvar target = {}\n\t\t\tfor (var prop in source)\n\t\t\t\tif (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)\n\t\t\t\t\ttarget[prop] = source[prop]\n\t\t\tif (source != null && __getOwnPropSymbols)\n\t`\n\n\t// Avoid \"of\" when not using ES6\n\tif !unsupportedJSFeatures.Has(compat.ForOf) {\n\t\ttext += `\n\t\t\t\tfor (var prop of __getOwnPropSymbols(source)) {\n\t\t`\n\t} else {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/internal/runtime/runtime.go#L120-L156","documentation":"This error is thrown by esbuild's generated `__glob` runtime helper, which is emitted into bundles that use glob-style imports (e.g. `import * from './dir/*.ts'`). The helper holds a static map from request path to a loader function built at bundle time; if at runtime the map is asked for a path that was not present when the bundle was generated, it throws. It is a runtime error in the *generated output*, not a build-time error from esbuild's API.","triggerScenarios":"Calling the generated `__glob(path)` helper (alias `__globImport`) with a path string that is not a key in the map esbuild produced. This happens when user code or another runtime resolves a dynamic path that wasn't matched by the glob during bundling — e.g. a path produced at runtime via string concatenation, a typo'd suffix, or a file that didn't exist on disk at build time but is requested at runtime.","commonSituations":"Bundling a glob like `./*.svg` and then trying to import a file added after the bundle was built; constructing the import path dynamically (template literals) so it no longer matches the static keys; migrating from another bundler that resolved globs lazily at runtime; SSR setups that re-evaluate the bundle against a different file tree than the one bundled.","solutions":["Rebuild the bundle so the glob map includes every path your runtime will request.","Switch from a runtime-constructed path to a literal import so esbuild can statically resolve it, or pre-compute the full set of paths and import each explicitly.","If paths are genuinely dynamic, load them outside the bundle (e.g. fetch at runtime) instead of going through the `__glob` helper.","Inspect the generated bundle's `__glob` map keys to see exactly which paths are available and reconcile against what your code requests."],"exampleFix":"// before\nconst name = getUserInput()\nconst mod = __glob(`./icons/${name}.svg`) // may miss\n\n// after\nimport * as icons from './icons/*'  // esbuild builds a complete map\nconst mod = icons[`./icons/${name}.svg`]\nif (!mod) throw new Error(`unknown icon: ${name}`)","handlingStrategy":"validation","validationCode":"// If you control call sites into a generated __glob map, check membership first.\nconst globMap: Record<string, () => any> = (globalThis as any).__esbuildGlobMap\nfunction safeGlobLoad(path: string) {\n  if (!globMap || !(path in globMap)) {\n    throw new Error(`Glob import not available at build time: ${path}`)\n  }\n  return globMap[path]()\n}","typeGuard":"function isKnownGlobPath(map: Record<string, unknown>, p: string): boolean {\n  return Object.prototype.hasOwnProperty.call(map, p)\n}","tryCatchPattern":null,"preventionTips":["Always rebuild after adding new files that a glob import should pick up.","Avoid constructing glob-import paths at runtime; prefer static imports.","Inspect the generated bundle's __glob map keys during development to confirm coverage.","Add a unit test that requests every path your runtime code will ask for."],"tags":["runtime","glob-imports","dynamic-import","bundle-output"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}