yamadashy/repomix · error
Failed to load language ${langName}: ${message}
Error message
Failed to load language ${langName}: ${message} What it means
loadLanguage resolves the per-language .wasm grammar file and loads it via Language.load. Any failure (resolution or load) is wrapped as 'Failed to load language <name>: <message>'. This is a plain Error, not RepomixError, and is later re-wrapped by prepareLang.
Source
Thrown at src/core/treeSitter/loadLanguage.ts:40
/**
* Get the WASM base path from environment variable or custom setting.
*/
function getWasmBasePath(): string | null {
return customWasmBasePath ?? process.env.REPOMIX_WASM_DIR ?? null;
}
export async function loadLanguage(langName: string): Promise<Language> {
if (!langName) {
throw new Error('Invalid language name');
}
try {
const wasmPath = await getWasmPath(langName);
return await Language.load(wasmPath);
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to load language ${langName}: ${message}`);
}
}
async function getWasmPath(langName: string): Promise<string> {
const wasmBasePath = getWasmBasePath();
let wasmPath: string;
if (wasmBasePath) {
// Use custom WASM path for bundled environments
wasmPath = path.join(wasmBasePath, `tree-sitter-${langName}.wasm`);
} else {
// Use require.resolve for standard node_modules environments
wasmPath = require.resolve(`@repomix/tree-sitter-wasms/out/tree-sitter-${langName}.wasm`);
}
try {
await fs.access(wasmPath);
return wasmPath;View on GitHub (pinned to f465ad9093)
Solutions
- Check the inlined message and verify the wasm path exists (ls the wasm base dir)
- Reinstall tree-sitter-wasms / node_modules to restore grammar files
- Point the wasm base path to a directory containing the required grammar wasms
- Rebuild grammars for the installed web-tree-sitter ABI if versions mismatch
Example fix
// before
getWasmBasePath = () => '/custom/stale-wasms';
// after
getWasmBasePath = () => path.dirname(require.resolve('tree-sitter-wasms/out/tree-sitter-typescript.wasm')); Defensive patterns
Strategy: validation
Validate before calling
import { access, constants } from 'node:fs/promises';
import path from 'node:path';
const wasmPath = path.join(getWasmBasePath(), `tree-sitter-${langName}.wasm`);
try { await access(wasmPath, constants.R_OK); }
catch { throw new Error(`grammar wasm missing: ${wasmPath}`); } Try / catch
try {
const lang = await loadLanguage('python');
} catch (err) {
if (String(err.message).startsWith('Failed to load language')) {
console.error('grammar wasm missing/incompatible — reinstall tree-sitter-wasms');
} else throw err;
} Prevention
- Keep tree-sitter-wasms and web-tree-sitter versions aligned in package.json
- Include *.wasm in production dependency artifacts
- After upgrades, smoke-test loading each supported language
- Log the resolved wasm path when customizing the base path
When it happens
Trigger: getWasmPath returns a path whose file is missing or unreadable, or Language.load fails on a corrupt/incompatible wasm (e.g. grammar built for a different tree-sitter ABI version).
Common situations: Partial npm install skipping optional tree-sitter-wasms artifacts; custom getWasmBasePath pointing to a directory that lacks the language wasm; upgraded web-tree-sitter with stale grammar wasms.
Related errors
- Failed to prepare language ${name}: ${message}
- Failed to initialize parser: ${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/f7a9aaee46fb0a8c.
Report an issue: GitHub.