microsoft/monaco-editor · error · Error
one parameter must be defined
Error message
one parameter must be defined
What it means
Thrown by the playground Source constructor when all three parameters (version, url, sourceLanguagesStr) are undefined. A Source must identify where to load Monaco from — either an npm version, a direct URL, or at minimum a languages-source string — so an all-undefined instance is meaningless and is rejected at construction. The static factories (useLatest, useLatestDev, parse) always supply at least one field; direct `new Source(undefined, undefined, undefined)` is the trigger.
Solutions
- Provide at least one of version, url, or sourceLanguagesStr when constructing Source directly.
- Prefer the static factories: `Source.useLatest()` or `Source.useLatestDev()` which always set a field.
- If using Source.parse, ensure the input resolves to a known form ('latest', 'latest-dev', or 'vX.Y.Z'), or supply a non-empty sourceLanguagesStr as the fallback.
- Validate upstream (query params/settings) so that at least one source field reaches the constructor.
Example fix
// before
const source = new Source(undefined, undefined, undefined); // throws
// after
const source = Source.useLatest(); // version = monacoEditorVersion
// or
const source = new Source('0.34.0', undefined, undefined); Defensive patterns
Strategy: type-guard
Validate before calling
function makeSource(version?: string, url?: string, langs?: string): Source {
if (version === undefined && url === undefined && langs === undefined) {
// fall back to a sensible default rather than constructing an invalid Source
return Source.useLatest();
}
return new Source(version, url, langs);
} Type guard
function hasAnySourceField(version: string | undefined, url: string | undefined, langs: string | undefined): boolean {
return version !== undefined || url !== undefined || langs !== undefined;
} Prevention
- Prefer the static factories (useLatest/useLatestDev) which always satisfy the invariant.
- When parsing user input, default to 'latest' if no recognizable source string is present.
- Validate playground query params upstream so an all-undefined Source is never constructed.
When it happens
Trigger: Constructing `new Source(undefined, undefined, undefined)` directly; a refactor that passes three optional values that all happen to be undefined; calling Source.parse with a sourceStr that is neither 'latest', 'latest-dev', nor a 'v'-prefixed version AND sourceLanguagesStr is also undefined (parse falls through to `new Source(undefined, sourceStr, ...)` where sourceStr is undefined).
Common situations: URL/playground query params missing the source and languageSource keys; a default-settings change that leaves both npmVersion and coreUrl unset; programmatic Source creation where the caller forgot to supply a value.
Related errors
- already initialized
- already initialized
- monaco is not loaded yet
- Invalid language id
- Renaming files is not supported.
AI-assisted analysis of microsoft/monaco-editor@ca1b42dc89 (2026-08-13).
Data as JSON: /api/errors/9e54fbe0ac1569fc.
Report an issue: GitHub.
Appendix: source
Thrown at website/src/website/pages/playground/Source.ts:55
public equals(other: Source | undefined): boolean {
if (!other) {
return false;
}
return other.toString() === this.toString();
}
constructor(
public readonly version: string | undefined,
public readonly url: string | undefined,
public readonly sourceLanguagesStr: string | undefined
) {
if (
version === undefined &&
url === undefined &&
sourceLanguagesStr === undefined
) {
throw new Error("one parameter must be defined");
}
}
sourceToString(): string | undefined {
if (this.url) {
return this.url;
}
if (this.version) {
return `v${this.version}`;
}
return undefined;
}
sourceLanguagesToString(): string | undefined {
return this.sourceLanguagesStr;
}
toString() {View on GitHub (pinned to ca1b42dc89)