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

  1. Read the inlined <message> for the root cause (wasm load vs query compile)
  2. Reinstall dependencies (rm -rf node_modules && npm ci) to restore wasm grammars
  3. Fix the language's query file so it matches the grammar's node names/version
  4. 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

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


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/b525d09a3e926920. Report an issue: GitHub.