{"record":{"id":"70128a8f96927fe9","repo":"denoland/deno","slug":"deno-jupyter-is-only-available-in-deno-jupyter-s","errorCode":null,"errorMessage":"Deno.jupyter is only available in `deno jupyter` subcommand","messagePattern":"Deno\\.jupyter is only available in `deno jupyter` subcommand","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"runtime/js/99_main.js","lineNumber":1131,"sourceCode":"\n    runtimeStart(\n      denoVersion,\n      v8Version,\n      tsVersion,\n      target,\n    );\n\n    // TODO(bartlomieju): this is not ideal, but because we use `ObjectAssign`\n    // above any properties that are defined elsewhere using `Object.defineProperty`\n    // are lost.\n    let jupyterNs = undefined;\n    ObjectDefineProperty(finalDenoNs, \"jupyter\", {\n      __proto__: null,\n      get() {\n        if (jupyterNs) {\n          return jupyterNs;\n        }\n        throw new Error(\n          \"Deno.jupyter is only available in `deno jupyter` subcommand\",\n        );\n      },\n      set(val) {\n        jupyterNs = val;\n      },\n    });\n\n    for (let i = 0; i <= unstableFeatures.length; i++) {\n      const id = unstableFeatures[i];\n      const unstable = denoNsUnstableById[id];\n      if (unstable) {\n        ObjectDefineProperties(\n          finalDenoNs,\n          getSafeOwnPropertyDescriptors(unstable),\n        );\n      }\n    }","sourceCodeStart":1113,"sourceCodeEnd":1149,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/runtime/js/99_main.js#L1113-L1149","documentation":"Deno.jupyter is published on the final Deno namespace in runtime/js/99_main.js as a lazy accessor: it caches the namespace once the `deno jupyter` bootstrap sets it, but until then the getter throws Error('Deno.jupyter is only available in `deno jupyter` subcommand'). Accessing the property under any other subcommand (deno run, test, repl) throws. Note the accessor property always exists, so presence checks like `'jupyter' in Deno` cannot detect availability — only an actual access inside try/catch can.","triggerScenarios":"`Deno.jupyter.broadcast('display_data', ...)` in a script run with `deno run`; notebook helper modules reused in plain scripts; probing capabilities by touching Deno.jupyter at import time.","commonSituations":"Sharing rich-output helpers between notebooks and CLI tools; libraries that enhance output when a kernel is present; version drift, since newer Deno releases expose the jupyter namespace in all subcommands.","solutions":["Access Deno.jupyter only behind a try/catch probe (see defense) or inside code known to run under `deno jupyter`","Route display output through console.log generally, and use Deno.jupyter only when the probe succeeds","Upgrade Deno if you need Deno.jupyter unconditionally — newer versions expose it in every subcommand"],"exampleFix":"// before\nDeno.jupyter.broadcast('display_data', { data: { 'text/html': html } });\n\n// after\nfunction getJupyter() {\n  try {\n    return Deno.jupyter;\n  } catch {\n    return undefined;\n  }\n}\nconst jupyter = getJupyter();\nif (jupyter) jupyter.broadcast('display_data', { data: { 'text/html': html } });","handlingStrategy":"try-catch","validationCode":"function getJupyter() {\n  try {\n    return Deno.jupyter; // touching the property throws outside deno jupyter\n  } catch {\n    return undefined;\n  }\n}\nconst jupyter = getJupyter();\nif (jupyter) {\n  jupyter.broadcast('display_data', payload);\n}","typeGuard":null,"tryCatchPattern":"// wrap every access — even detection — because the getter throws\ntry {\n  const { markdown } = Deno.jupyter;\n  await markdown(md);\n} catch {\n  console.log(md); // plain fallback outside notebooks\n}","preventionTips":["The accessor property always exists, so `'jupyter' in Deno` cannot detect availability — probe by accessing inside try/catch","Isolate notebook-specific output helpers behind one guarded accessor","Upgrade Deno if you need Deno.jupyter outside `deno jupyter`; newer versions expose it in every subcommand"],"tags":["jupyter","namespace","subcommand","feature-detection","getter"],"backgroundTag":"wrong-subcommand-context","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}