{"record":{"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":1174,"sourceCode":"      }\n    } finally {\n      await build.close()\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":1156,"sourceCodeEnd":1192,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/optimizer/index.ts#L1156-L1192","documentation":"Thrown while computing exports data for an optimized dependency entry: the file could not be parsed by oxc's default parser, the inferred `lang` (from `rolldownOptions.moduleTypes` or file extension) is not one of jsx/tsx/ts, so the fallback `transformWithOxc` retry path is not allowed. The entry's exports therefore cannot be introspected for interop.","triggerScenarios":"index.ts:1167 first tries `parse(entryContent)`; on failure (line 1173) it checks `lang` resolved from `moduleTypes[extname]` (default 'jsx'). If lang is not jsx/tsx/ts (e.g. a custom module type like 'css', 'json', 'text'), line 1174 throws instead of attempting a transform.","commonSituations":"A dependency ships an entry with non-standard syntax (e.g. Flow, non-standard decorators) that oxc cannot parse. A custom `optimizeDeps.rolldownOptions.moduleTypes` maps the file's extension to a non-JS loader. A dependency exposes a JSON or binary-like file as its main entry. Corrupt/truncated file in node_modules.","solutions":["Move the problematic package into `optimizeDeps.exclude` so Vite does not pre-bundle/parse its entry.","Add it to `optimizeDeps.include` only if you can also supply a working `moduleTypes` mapping that yields jsx/tsx/ts.","Upgrade or pin the dependency to a version whose main entry is valid ESM/CJS that oxc parses.","Reinstall the package (`rm -rf node_modules/<pkg> && npm install`) if the file looks truncated.","If the syntax is Flow/decorators, transpile the dependency separately or alias it to a pre-built artifact."],"exampleFix":"// before\nexport default defineConfig({})\n// error: Unable to parse: node_modules/some-pkg/dist/index.flow.js\n\n// after\nexport default defineConfig({\n  optimizeDeps: { exclude: ['some-pkg'] },\n})","handlingStrategy":"validation","validationCode":"import { parse } from 'oxc-parser'\nimport fs from 'node:fs'\n\nfunction canParseEntry(file: string): boolean {\n  try { parse(fs.readFileSync(file, 'utf-8')); return true }\n  catch { return false }\n}\n// before relying on optimizeDeps.include for a dep, verify its entry parses or exclude it\nconst ok = canParseEntry(require.resolve('some-pkg'))\nif (!ok) config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), 'some-pkg']","typeGuard":null,"tryCatchPattern":"try {\n  await server.listen()\n} catch (e) {\n  if (e instanceof Error && /Unable to parse:/.test(e.message)) {\n    const file = e.message.match(/Unable to parse: (.*)\\./)?.[1]\n    console.warn(`Optimizer cannot parse ${file}; adding to optimizeDeps.exclude and retrying.`)\n    config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), pathToPackage(file)]\n    // retry server start\n  } else throw e\n}","preventionTips":["Pin dependencies whose main entry is valid ESM/CJS that oxc parses.","Keep optimizeDeps.rolldownOptions.moduleTypes restricted to jsx/tsx/ts for JS-family files.","Reinstall dependencies when an entry looks corrupted."],"tags":["optimizer","parser","oxc","dependencies"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}