{"record":{"id":"46d3f567ffd5d398","repo":"microsoft/monaco-editor","slug":"monaco-is-not-loaded-yet","errorCode":null,"errorMessage":"monaco is not loaded yet","messagePattern":"monaco is not loaded yet","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"website/src/monaco-loader.ts","lineNumber":8,"sourceCode":"/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nexport function getLoadedMonaco(): typeof monaco {\n\tif (!monaco) {\n\t\tthrow new Error(\"monaco is not loaded yet\");\n\t}\n\treturn monaco;\n}\n\nexport function getMonaco(): typeof monaco | undefined {\n\treturn (window as any).monaco;\n}\n\nexport type IAMDMonacoSetup = {\n\tloaderUrl: string;\n\tloaderConfigPaths: Record<string, string>;\n\tcodiconUrl: string;\n\tmonacoTypesUrl: string | undefined;\n\tlanguage?: string;\n};\n\nexport type IESMMonacoSetup = {\n\tesmUrl: string;","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/microsoft/monaco-editor/blob/ca1b42dc896b99db78e1c743256e8654e12cea2d/website/src/monaco-loader.ts#L1-L26","documentation":"Thrown by getLoadedMonaco() in the website's monaco-loader when the module-level `monaco` binding is still undefined. The loader exposes loadMonaco()/waitForLoadedMonaco() as the async path that actually imports/configures Monaco, and getLoadedMonaco() as a synchronous accessor usable only after loading completes. Calling it before the load promise resolves violates the contract and throws, signalling a race where consumer code ran too early.","triggerScenarios":"Calling getLoadedMonaco() synchronously at module init, in a render, or in an event handler before loadMonaco() has been awaited; assuming Monaco is available because the script tag was added but the AMD require callback hasn't fired yet.","commonSituations":"A React/Vue component calls getLoadedMonaco() in its setup before the parent triggered loadMonaco(); test code that mounts the playground without booting the loader; refactoring that removed or reordered the loadMonaco() call.","solutions":["Await loadMonaco(setup) (or waitForLoadedMonaco()) before calling getLoadedMonaco().","Gate any code that needs Monaco behind the resolved load promise (e.g. `await waitForLoadedMonaco(); const m = getLoadedMonaco();`).","If you only need the value optionally, use getMonaco() which returns undefined instead of throwing.","Ensure loadMonaco() is invoked exactly once at app boot, before any consumer tries to read Monaco."],"exampleFix":"// before\nconst monaco = getLoadedMonaco(); // throws if not yet loaded\nmonaco.editor.create(...);\n// after\nawait loadMonaco(setup);\nconst monaco = getLoadedMonaco();\nmonaco.editor.create(...);","handlingStrategy":"validation","validationCode":"// ensure load has completed before any synchronous read\nawait loadMonaco(setup); // or await waitForLoadedMonaco();\nif (!getMonaco()) {\n  throw new Error('Monaco failed to load');\n}\nconst monaco = getLoadedMonaco(); // now safe","typeGuard":"function isMonacoLoaded(): boolean {\n  return typeof (window as any).monaco !== 'undefined';\n}","tryCatchPattern":null,"preventionTips":["Always await loadMonaco()/waitForLoadedMonaco() before calling getLoadedMonaco().","Use getMonaco() for optional access — it returns undefined instead of throwing.","Centralize the load call at app boot so consumers can assume it's done."],"tags":["runtime","website","initialization","async","monaco-loader"],"backgroundTag":null,"analyzedSha":"ca1b42dc896b99db78e1c743256e8654e12cea2d","analyzedAt":"2026-08-13T02:00:51.380Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}