microsoft/monaco-editor · error · Error
monaco is not loaded yet
Error message
monaco is not loaded yet
What it means
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.
Source
Thrown at website/src/monaco-loader.ts:8
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function getLoadedMonaco(): typeof monaco {
if (!monaco) {
throw new Error("monaco is not loaded yet");
}
return monaco;
}
export function getMonaco(): typeof monaco | undefined {
return (window as any).monaco;
}
export type IAMDMonacoSetup = {
loaderUrl: string;
loaderConfigPaths: Record<string, string>;
codiconUrl: string;
monacoTypesUrl: string | undefined;
language?: string;
};
export type IESMMonacoSetup = {
esmUrl: string;View on GitHub (pinned to ca1b42dc89)
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.
Example fix
// before const monaco = getLoadedMonaco(); // throws if not yet loaded monaco.editor.create(...); // after await loadMonaco(setup); const monaco = getLoadedMonaco(); monaco.editor.create(...);
Defensive patterns
Strategy: validation
Validate before calling
// ensure load has completed before any synchronous read
await loadMonaco(setup); // or await waitForLoadedMonaco();
if (!getMonaco()) {
throw new Error('Monaco failed to load');
}
const monaco = getLoadedMonaco(); // now safe Type guard
function isMonacoLoaded(): boolean {
return typeof (window as any).monaco !== 'undefined';
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- already initialized
- already initialized
- one parameter must be defined
- You must define a function MonacoEnvironment.getWorkerUrl or
- Invalid language id: ${this._languageId}
AI-assisted analysis of microsoft/monaco-editor@ca1b42dc89 (2026-08-13).
Data as JSON: /api/errors/46d3f567ffd5d398.
Report an issue: GitHub.