vitejs/vite · error · Error

Unable to parse: .

Error message

Unable to parse: ${filePath}.

What it means

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.

Solutions

  1. Move the problematic package into `optimizeDeps.exclude` so Vite does not pre-bundle/parse its entry.
  2. Add it to `optimizeDeps.include` only if you can also supply a working `moduleTypes` mapping that yields jsx/tsx/ts.
  3. Upgrade or pin the dependency to a version whose main entry is valid ESM/CJS that oxc parses.
  4. Reinstall the package (`rm -rf node_modules/<pkg> && npm install`) if the file looks truncated.
  5. If the syntax is Flow/decorators, transpile the dependency separately or alias it to a pre-built artifact.

Example fix

// before
export default defineConfig({})
// error: Unable to parse: node_modules/some-pkg/dist/index.flow.js

// after
export default defineConfig({
  optimizeDeps: { exclude: ['some-pkg'] },
})
Defensive patterns

Strategy: validation

Validate before calling

import { parse } from 'oxc-parser'
import fs from 'node:fs'

function canParseEntry(file: string): boolean {
  try { parse(fs.readFileSync(file, 'utf-8')); return true }
  catch { return false }
}
// before relying on optimizeDeps.include for a dep, verify its entry parses or exclude it
const ok = canParseEntry(require.resolve('some-pkg'))
if (!ok) config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), 'some-pkg']

Try / catch

try {
  await server.listen()
} catch (e) {
  if (e instanceof Error && /Unable to parse:/.test(e.message)) {
    const file = e.message.match(/Unable to parse: (.*)\./)?.[1]
    console.warn(`Optimizer cannot parse ${file}; adding to optimizeDeps.exclude and retrying.`)
    config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), pathToPackage(file)]
    // retry server start
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/45d7afb4ad206af1. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/node/optimizer/index.ts:1174

      }
    } finally {
      await build.close()
    }
  }

  let parseResult: ReturnType<typeof parse>
  let usedJsxLoader = false

  const entryContent = fs.readFileSync(filePath, 'utf-8')
  try {
    parseResult = parse(entryContent)
  } catch {
    const lang = rolldownOptions.moduleTypes?.[path.extname(filePath)] || 'jsx'
    debug?.(
      `Unable to parse: ${filePath}.\n Trying again with a ${lang} transform.`,
    )
    if (lang !== 'jsx' && lang !== 'tsx' && lang !== 'ts') {
      throw new Error(`Unable to parse: ${filePath}.`)
    }
    const transformed = await transformWithOxc(
      entryContent,
      filePath,
      { lang },
      undefined,
      environment.config,
    )
    parseResult = parse(transformed.code)
    usedJsxLoader = true
  }

  const [, exports, , hasModuleSyntax] = parseResult
  const exportsData: ExportsData = {
    hasModuleSyntax,
    exports: exports.map((e) => e.n),
    jsxLoader: usedJsxLoader,
  }

View on GitHub (pinned to b4d66fee14)