yamadashy/repomix · critical · RepomixError

Failed to initialize parser: ${message}

Error message

Failed to initialize parser: ${message}

What it means

LanguageParser.init() calls web-tree-sitter's Parser.init() to load the tree-sitter runtime wasm. If that fails, it wraps the error as 'Failed to initialize parser: <message>' and the parser remains uninitialized, so all subsequent language calls will also fail.

Source

Thrown at src/core/treeSitter/languageParser.ts:104

    const ext = this.getFileExtension(filePath);
    const config = getLanguageConfigByExtension(ext);
    if (!config) {
      logger.debug(`No language configuration found for extension: ${ext}`);
    }
    return config?.name;
  }

  public async init(): Promise<void> {
    if (this.initialized) {
      return;
    }

    try {
      await Parser.init();
      this.initialized = true;
    } catch (error) {
      const message = error instanceof Error ? error.message : String(error);
      throw new RepomixError(`Failed to initialize parser: ${message}`);
    }
  }

  public async dispose(): Promise<void> {
    for (const resources of this.loadedResources.values()) {
      resources.parser.delete();
      logger.debug(`Deleted parser for language: ${resources.lang}`);
    }
    this.loadedResources.clear();
    this.initialized = false;
  }
}

View on GitHub (pinned to f465ad9093)

Solutions

  1. Ensure the web-tree-sitter runtime .wasm is resolvable — reinstall the package and clear bundler caches
  2. If bundling, configure copy/asset rules for tree-sitter.wasm (or use the tree-sitter-wasms package path option)
  3. Check Node version compatibility with web-tree-sitter
  4. Retry after environment fix; the message inlines the underlying cause

Example fix

// before (vite): wasm treated as JS import
import { Parser } from 'web-tree-sitter';
// after: ensure asset copied
optimizeDeps: { exclude: ['web-tree-sitter'] } // and copy tree-sitter.wasm to output
Defensive patterns

Strategy: try-catch

Validate before calling

import { access, constants } from 'node:fs/promises';
import path from 'node:path';
const runtimeWasm = path.join(path.dirname(require.resolve('web-tree-sitter')), 'tree-sitter.wasm');
await access(runtimeWasm, constants.R_OK); // fail fast before Parser.init()

Try / catch

const parser = new LanguageParser();
try {
  await parser.init();
} catch (err) {
  console.error(`tree-sitter runtime unavailable: ${err.message}`); // fallback path or abort
}

Prevention

When it happens

Trigger: Parser.init() rejects — typically because the tree-sitter runtime wasm file cannot be located or loaded (missing package asset, bad base path, restricted fs/network), or the Node/WASM runtime is incompatible.

Common situations: Bundlers (webpack/vite/esbuild) not shipping web-tree-sitter's .wasm asset; running in a sandbox without the node_modules tree-sitter.wasm; tree-sitter version mismatch between runtime and grammars.

Related errors


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