{"record":{"id":"ea55591865dec52a","repo":"yamadashy/repomix","slug":"failed-to-initialize-parser-message","errorCode":null,"errorMessage":"Failed to initialize parser: ${message}","messagePattern":"Failed to initialize parser: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"critical","filePath":"src/core/treeSitter/languageParser.ts","lineNumber":104,"sourceCode":"    const ext = this.getFileExtension(filePath);\n    const config = getLanguageConfigByExtension(ext);\n    if (!config) {\n      logger.debug(`No language configuration found for extension: ${ext}`);\n    }\n    return config?.name;\n  }\n\n  public async init(): Promise<void> {\n    if (this.initialized) {\n      return;\n    }\n\n    try {\n      await Parser.init();\n      this.initialized = true;\n    } catch (error) {\n      const message = error instanceof Error ? error.message : String(error);\n      throw new RepomixError(`Failed to initialize parser: ${message}`);\n    }\n  }\n\n  public async dispose(): Promise<void> {\n    for (const resources of this.loadedResources.values()) {\n      resources.parser.delete();\n      logger.debug(`Deleted parser for language: ${resources.lang}`);\n    }\n    this.loadedResources.clear();\n    this.initialized = false;\n  }\n}\n","sourceCodeStart":86,"sourceCodeEnd":117,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/treeSitter/languageParser.ts#L86-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (vite): wasm treated as JS import\nimport { Parser } from 'web-tree-sitter';\n// after: ensure asset copied\noptimizeDeps: { exclude: ['web-tree-sitter'] } // and copy tree-sitter.wasm to output","handlingStrategy":"try-catch","validationCode":"import { access, constants } from 'node:fs/promises';\nimport path from 'node:path';\nconst runtimeWasm = path.join(path.dirname(require.resolve('web-tree-sitter')), 'tree-sitter.wasm');\nawait access(runtimeWasm, constants.R_OK); // fail fast before Parser.init()","typeGuard":null,"tryCatchPattern":"const parser = new LanguageParser();\ntry {\n  await parser.init();\n} catch (err) {\n  console.error(`tree-sitter runtime unavailable: ${err.message}`); // fallback path or abort\n}","preventionTips":["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"],"tags":["tree-sitter","wasm","initialization"],"backgroundTag":"wasm-load-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}