yamadashy/repomix · error · RepomixError
Failed to prepare language ${name}: ${message}
Error message
Failed to prepare language ${name}: ${message} What it means
prepareLang's outer catch-all: any failure while loading the wasm grammar, creating the Parser, setting the language, or compiling the query is rethrown as 'Failed to prepare language <name>: <message>'. The original message is inlined so the root cause is visible.
Source
Thrown at src/core/treeSitter/languageParser.ts:54
// Create strategy instance lazily when first needed
// NOTE: Strategy instances are cached per language in this.loadedResources
// and shared across all files of the same language. This is safe because
// all current strategies are stateless and only use the parameters passed
// to their parseCapture method.
const strategy = config.createStrategy();
const resources: LanguageResources = {
lang: name,
parser,
query,
strategy,
};
this.loadedResources.set(name, resources);
return resources;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new RepomixError(`Failed to prepare language ${name}: ${message}`);
}
}
private async getResources(name: SupportedLang): Promise<LanguageResources> {
if (!this.initialized) {
throw new RepomixError('LanguageParser is not initialized. Call init() first.');
}
const resources = this.loadedResources.get(name);
if (!resources) {
return this.prepareLang(name);
}
return resources;
}
public async getParserForLang(name: SupportedLang): Promise<Parser> {
const resources = await this.getResources(name);
return resources.parser;View on GitHub (pinned to f465ad9093)
Solutions
- Read the inlined <message> for the root cause (wasm load vs query compile)
- Reinstall dependencies (rm -rf node_modules && npm ci) to restore wasm grammars
- Fix the language's query file so it matches the grammar's node names/version
- If a wasm is corrupt, rebuild it (npm run language-* scripts) or re-download
Defensive patterns
Strategy: try-catch
Type guard
const isRepomixError = (e: unknown): e is RepomixError => e instanceof RepomixError;
Try / catch
try {
await parser.init();
const res = await parser.getResources(lang);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes('Failed to prepare language')) {
console.error(`tree-sitter setup failed for ${lang}: ${msg}`); // falls back to regex-based tokenization
} else throw err;
} Prevention
- Reinstall node_modules after upgrading tree-sitter/web-tree-sitter
- Validate query files against the grammar version in CI
- Keep grammar wasm artifacts in lockstep with query syntax
- Log the inner cause for faster triage
When it happens
Trigger: loadLanguage throws (missing/corrupt wasm), new Query() fails due to invalid query syntax for the grammar version, parser.setLanguage rejects an incompatible Language, or the config query is empty/malformed.
Common situations: Stale or mismatched tree-sitter wasm artifacts after upgrading tree-sitter; corrupted node_modules; a newly added query referencing nodes that don't exist in the grammar version.
Related errors
- Failed to initialize parser: ${message}
- Failed to load language ${langName}: ${message}
- WASM file not found for language ${langName}: ${wasmPath}
- Language configuration not found for: ${name}
- Failed to compress ${filePath}, using uncompressed content:
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/b525d09a3e926920.
Report an issue: GitHub.