{"record":{"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/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/runtime/runtime.go#L120-L156","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst mods = import.meta.glob('./pages/*.js')\nconst mod = mods[userPath]()  // throws if userPath not in map\n\n// after\nconst mods = import.meta.glob('./pages/*.js')\nconst loader = mods[userPath]\nif (loader) {\n  const mod = loader()\n} else {\n  // handle missing module\n}","handlingStrategy":"validation","validationCode":"// Before indexing a glob-import map, confirm the key exists.\nconst mods = import.meta.glob('./pages/*.js')\nconst key = someUserPath\nif (Object.prototype.hasOwnProperty.call(mods, key)) {\n  const mod = mods[key]()\n} else {\n  throw new Error(`Unknown module path: ${key}`)\n}","typeGuard":"// Narrow a glob map entry to a callable loader.\nconst isGlobLoader = (v: unknown): v is () => unknown =>\n  typeof v === 'function'\n\nconst loader = mods[key]\nif (isGlobLoader(loader)) loader()\nelse throw new Error(`No glob entry for ${key}`)","tryCatchPattern":null,"preventionTips":["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."],"tags":["glob","runtime","dynamic-import","bundle"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}