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
- Ensure the web-tree-sitter runtime .wasm is resolvable — reinstall the package and clear bundler caches
- If bundling, configure copy/asset rules for tree-sitter.wasm (or use the tree-sitter-wasms package path option)
- Check Node version compatibility with web-tree-sitter
- 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
- Configure bundlers to copy web-tree-sitter's .wasm as an asset
- Pin web-tree-sitter versions and test parser init in CI on all platforms
- Don't prune node_modules/.wasm in production Docker images
- Check the runtime wasm path resolves in serverless/edge environments
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
- Failed to prepare language ${name}: ${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/ea55591865dec52a.
Report an issue: GitHub.