{"record":{"id":"f7a9aaee46fb0a8c","repo":"yamadashy/repomix","slug":"failed-to-load-language-langname-message","errorCode":null,"errorMessage":"Failed to load language ${langName}: ${message}","messagePattern":"Failed to load language (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/treeSitter/loadLanguage.ts","lineNumber":40,"sourceCode":"\n/**\n * Get the WASM base path from environment variable or custom setting.\n */\nfunction getWasmBasePath(): string | null {\n  return customWasmBasePath ?? process.env.REPOMIX_WASM_DIR ?? null;\n}\n\nexport async function loadLanguage(langName: string): Promise<Language> {\n  if (!langName) {\n    throw new Error('Invalid language name');\n  }\n\n  try {\n    const wasmPath = await getWasmPath(langName);\n    return await Language.load(wasmPath);\n  } catch (error: unknown) {\n    const message = error instanceof Error ? error.message : String(error);\n    throw new Error(`Failed to load language ${langName}: ${message}`);\n  }\n}\n\nasync function getWasmPath(langName: string): Promise<string> {\n  const wasmBasePath = getWasmBasePath();\n\n  let wasmPath: string;\n  if (wasmBasePath) {\n    // Use custom WASM path for bundled environments\n    wasmPath = path.join(wasmBasePath, `tree-sitter-${langName}.wasm`);\n  } else {\n    // Use require.resolve for standard node_modules environments\n    wasmPath = require.resolve(`@repomix/tree-sitter-wasms/out/tree-sitter-${langName}.wasm`);\n  }\n\n  try {\n    await fs.access(wasmPath);\n    return wasmPath;","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/treeSitter/loadLanguage.ts#L22-L58","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\ngetWasmBasePath = () => '/custom/stale-wasms';\n// after\ngetWasmBasePath = () => path.dirname(require.resolve('tree-sitter-wasms/out/tree-sitter-typescript.wasm'));","handlingStrategy":"validation","validationCode":"import { access, constants } from 'node:fs/promises';\nimport path from 'node:path';\nconst wasmPath = path.join(getWasmBasePath(), `tree-sitter-${langName}.wasm`);\ntry { await access(wasmPath, constants.R_OK); }\ncatch { throw new Error(`grammar wasm missing: ${wasmPath}`); }","typeGuard":null,"tryCatchPattern":"try {\n  const lang = await loadLanguage('python');\n} catch (err) {\n  if (String(err.message).startsWith('Failed to load language')) {\n    console.error('grammar wasm missing/incompatible — reinstall tree-sitter-wasms');\n  } else throw err;\n}","preventionTips":["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"],"tags":["tree-sitter","wasm","grammar"],"backgroundTag":"wasm-load-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}