withastro/astro · warning

Language does not exist: ${lang}

Error message

Language does not exist: ${lang}

What it means

The workerd (Cloudflare runtime) build of astro-prism's language loader fetches Prism grammars on demand. When asked to load an id that is not present in prismjs' component index, it warns 'Language does not exist' and skips it — unless `loadLanguages.silent` is set. Highlighting for that language then falls back to plain text inside the code class.

Source

Thrown at packages/astro-prism/src/loadLanguages-workerd.ts:78

 * @returns {Promise<void>}
 */
export async function loadLanguages(languages: string | string[]) {
	prismRefCounter.increment();

	if (languages === undefined) {
		languages = Object.keys(components.languages).filter((l) => l !== 'meta');
	} else if (!Array.isArray(languages)) {
		languages = [languages];
	}

	// the user might have loaded languages via some other way or used `prism.js` which already includes some
	// we don't need to validate the ids because `getLoader` will ignore invalid ones
	const loaded = [...loadedLanguages, ...Object.keys(Prism.languages)];

	await getLoader(components, languages, loaded).load(async (lang: string) => {
		if (!(lang in components.languages)) {
			if (!loadLanguages.silent) {
				console.warn('Language does not exist: ' + lang);
			}
			return;
		}

		// remove from Prism
		delete Prism.languages[lang];

		if (Object.hasOwn(bundledLanguages, lang)) {
			await bundledLanguages[lang]();
		}

		loadedLanguages.add(lang);
	}, loadChainer);

	prismRefCounter.decrement();
}

/**

View on GitHub (pinned to 52e6c34790)

Solutions

  1. Verify the id exists in prismjs' components index (node_modules/prismjs/components.json) and fix the list
  2. If unknown ids are intentional (custom pre-registered grammars), set `loadLanguages.silent = true` to suppress the warning
  3. Register the custom grammar on Prism.languages before load so later code can still highlight it

Example fix

// before
loadLanguages(['typescript', 'mylang']);

// after
Prism.languages['mylang'] = myGrammar; // pre-register
loadLanguages(['typescript']);
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate the language list against prismjs' component index up front
import components from 'prismjs/components.json';
const known = (l: string) => l in components.languages;
const bad = requestedLanguages.filter((l) => !known(l) && !customRegistered.has(l));
if (bad.length) throw new Error(`unknown prism languages: ${bad.join(', ')}`);

Type guard

const isLoadablePrismLanguage = (lang: string): boolean =>
  lang !== 'meta' && lang in components.languages;

Prevention

When it happens

Trigger: Calling `loadLanguages` with ids absent from prismjs' components.json; a languages config list reused between Node and Workers environments where the id resolves in one but not the other.

Common situations: Typos in configured language lists; prismjs versions lacking a newer grammar; shared highlight config between serverless runtimes.

Related errors


AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18). Data as JSON: /api/errors/e2e0f08b9872746f. Report an issue: GitHub.