{"id":"45d7afb4ad206af1","repo":"vitejs/vite","slug":"unable-to-parse-filepath","errorCode":null,"errorMessage":"Unable to parse: ${filePath}.","messagePattern":"Unable to parse: (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/optimizer/index.ts","lineNumber":1170,"sourceCode":"    return {\n      hasModuleSyntax,\n      exports: exports.map((e) => e.n),\n    }\n  }\n\n  let parseResult: ReturnType<typeof parse>\n  let usedJsxLoader = false\n\n  const entryContent = fs.readFileSync(filePath, 'utf-8')\n  try {\n    parseResult = parse(entryContent)\n  } catch {\n    const lang = rolldownOptions.moduleTypes?.[path.extname(filePath)] || 'jsx'\n    debug?.(\n      `Unable to parse: ${filePath}.\\n Trying again with a ${lang} transform.`,\n    )\n    if (lang !== 'jsx' && lang !== 'tsx' && lang !== 'ts') {\n      throw new Error(`Unable to parse: ${filePath}.`)\n    }\n    const transformed = await transformWithOxc(\n      entryContent,\n      filePath,\n      { lang },\n      undefined,\n      environment.config,\n    )\n    parseResult = parse(transformed.code)\n    usedJsxLoader = true\n  }\n\n  const [, exports, , hasModuleSyntax] = parseResult\n  const exportsData: ExportsData = {\n    hasModuleSyntax,\n    exports: exports.map((e) => e.n),\n    jsxLoader: usedJsxLoader,\n  }","sourceCodeStart":1152,"sourceCodeEnd":1188,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/optimizer/index.ts#L1152-L1188","documentation":"While extracting a dependency's exports, Vite first parses the entry with oxc; if that fails it retries through a configured `moduleTypes` loader (defaulting to `jsx`). If the resolved loader is not one of `jsx`/`tsx`/`ts`, there is no fallback transform and it throws at optimizer/index.ts:1170. This guards against unsupported file types reaching the optimizer.","triggerScenarios":"A dependency whose entry file has an extension mapped to a non-JS moduleType in `optimizeDeps.esbuildOptions.moduleTypes`/`build.moduleTypes` (e.g. `.txt`, `.wasm`, a custom loader), or a file oxc cannot parse and whose configured loader isn't jsx/tsx/ts.","commonSituations":"A package ships a non-standard entry extension; user sets `esbuildOptions.loader`/`moduleTypes` to map an extension to `text`/`base64`/`json` and that file ends up as a dep entry; corrupt or transpiled-with-syntax-not-supported-by-oxc files.","solutions":["Ensure the dependency's entry is real JS/TS; if the package points `main`/`module` at a non-JS file, file an issue with the package or alias it.","Map the extension to `jsx`/`tsx`/`ts` in `optimizeDeps.esbuildOptions` so the fallback transform can run.","Add the package to `optimizeDeps.exclude` so the optimizer doesn't try to pre-bundle it.","Update the package — newer versions often fix entry/metadata issues."],"exampleFix":"// before\noptimizeDeps: { esbuildOptions: { loader: { '.myext': 'text' } } }\n\n// after\noptimizeDps: { exclude: ['problematic-pkg'] }\n// or\noptimizeDeps: { esbuildOptions: { loader: { '.myext': 'jsx' } } }","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set(['jsx', 'tsx', 'ts'])\nfunction assertLoaderFor(ext: string, moduleTypes: Record<string, string>) {\n  const lang = moduleTypes[ext] || 'jsx'\n  if (!SUPPORTED.has(lang)) throw new Error(`Optimizer cannot parse .${ext}; map it to jsx/tsx/ts or exclude the dep`)\n}","typeGuard":"function isOptimizableLoader(lang: string): boolean {\n  return lang === 'jsx' || lang === 'tsx' || lang === 'ts'\n}","tryCatchPattern":null,"preventionTips":["Keep dependency entries as standard .js/.ts/.jsx/.tsx.","Don't map JS-adjacent extensions to text/base64 in optimizeDeps.esbuildOptions.","Add problematic packages to optimizeDeps.exclude."],"tags":["optimizer","parsing","dependencies","esbuild-options"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}