{"record":{"id":"06c0b3fe57e86478","repo":"denoland/deno","slug":"deno-bundle-is-not-available-in-compiled-binarie","errorCode":null,"errorMessage":"Deno.bundle() is not available in compiled binaries (`deno compile`). Run with `deno run` instead, or pre-bundle the entrypoints at build time.","messagePattern":"Deno\\.bundle\\(\\) is not available in compiled binaries \\(`deno compile`\\)\\. Run with `deno run` instead, or pre-bundle the entrypoints at build time\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ext/bundle/src/lib.rs","lineNumber":52,"sourceCode":"    } else {\n      state.put::<Arc<dyn BundleProvider>>(Arc::new(()));\n    }\n  },\n);\n\n#[async_trait]\nimpl BundleProvider for () {\n  async fn bundle(\n    &self,\n    _options: BundleOptions,\n    _permissions: PermissionsContainer,\n  ) -> Result<BuildResponse, AnyError> {\n    // Embedders that don't wire up a real provider (notably `denort`, used\n    // by `deno compile` outputs) fall through to this no-op implementation.\n    // Surface that limitation directly to the user instead of leaking the\n    // historical \"default BundleProvider does not do anything\" string.\n    // See denoland/deno#31597.\n    Err(deno_core::anyhow::anyhow!(\n      \"Deno.bundle() is not available in compiled binaries (`deno compile`). \\\n       Run with `deno run` instead, or pre-bundle the entrypoints at build time.\"\n    ))\n  }\n}\n\n#[async_trait]\npub trait BundleProvider: Send + Sync {\n  async fn bundle(\n    &self,\n    options: BundleOptions,\n    permissions: PermissionsContainer,\n  ) -> Result<BuildResponse, AnyError>;\n}\n\n#[derive(Clone, Debug, Eq, PartialEq, Default, FromV8)]\npub struct BundleOptions {\n  pub entrypoints: Vec<String>,","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/bundle/src/lib.rs#L34-L70","documentation":"Deno.bundle() needs the compiler/bundler machinery that only the full CLI wires up. Compiled binaries produced by `deno compile` use the denort runtime, which registers the no-op BundleProvider for `()` (ext/bundle/src/lib.rs:43-56); calling Deno.bundle() there surfaces this explicit error — a deliberate improvement over the old \"default BundleProvider does not do anything\" string (denoland/deno#31597).","triggerScenarios":"Compiling an app with `deno compile -o app main.ts` whose code path calls Deno.bundle(...); bundling-on-demand logic that works under `deno run` but ships inside a compiled executable.","commonSituations":"CLI tools that offer a `bundle` subcommand by calling Deno.bundle at runtime; pipelines ported from `deno bundle`; feature-detecting code that assumed the API exists everywhere.","solutions":["Run the program with `deno run` when it needs to bundle.","Pre-bundle entrypoints at build time (before deno compile) and embed/ship the emitted files instead of bundling at runtime.","Feature-detect and degrade gracefully: guard the call and emit a clear message when running inside a compiled binary."],"exampleFix":"// before\nconst result = await Deno.bundle(entry);   // throws inside `deno compile` output\n\n// after — pre-bundle at build time and embed\ndeno eval 'const r = await Deno.bundle(\"./src/entry.ts\"); await Deno.writeTextFile(\"dist/bundle.json\", JSON.stringify(r));'\n// then in the compiled app, read the embedded dist/bundle.json instead of calling Deno.bundle()","handlingStrategy":"fallback","validationCode":"// Detect a compiled binary before attempting to bundle at runtime\nconst isCompiled = Deno.execPath().endsWith(Deno.mainModule.replace(/^.*\\//, \"\")) === false\n  || !(await Deno.stat(Deno.mainModule.replace(\"file://\", \"\")).catch(() => null));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-bundle entrypoints during build and embed the artifacts instead of bundling at runtime.","Feature-detect the bundler: try Deno.bundle on a trivial module at startup and fall back to embedded output.","Keep bundle-on-demand code paths out of anything shipped via deno compile."],"tags":["bundle","compile","denort","runtime-api"],"backgroundTag":"api-unavailable-in-compiled-binary","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}