Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

Vite stops at startup while crawling your files for dependencies

Your error

Failed to scan for dependencies from entries:2 more lines it can show

Fix it fast

Most common cause, 1 of 4

A source file reached by the crawl does not parse

Repair the code at that position, for example a leftover merge marker, an unclosed bracket or an import line typed only halfway.

Fix
npx vite --force
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Vite 7 and 8 print Failed to scan for dependencies from entries when the pre-bundle crawl reaches a file it cannot parse; the parser error that names the file and line follows the entry list. Fix that code. JSX inside a .js file needs a .jsx name, and stray HTML pages need optimizeDeps.entries set to the real entry.

  • Applies to Vite 8.3, Vite 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Start the dev server again with the pre-bundle cache ignored and the deps debug log switched on. The log shows each entry the crawl begins from, and the lines after the entry list name the file and position that could not be parsed.

Run this first
npx vite --force --debug deps

Then find the line you see in this list and open its fix:

  1. 1A source file reached by the crawl does not parseBelow the entry list: a parse error with a path inside src and a line number
  2. 2JSX is written inside a file that ends in .jsThe JSX syntax extension is not currently enabled (Vite 7, where esbuild runs the crawl)
  3. 3The crawl includes HTML pages that are not part of the appThe entry list names .html files from places like a docs folder, a copied template or an old output folder
  4. 4A Vue or Svelte script block holds TypeScript but has no lang attributeThe parse error points at a .vue or .svelte file, with ?id= and a number after the file name

What does the error look like?

  • Failed to scan for dependencies from entries:
  • The JSX syntax extension is not currently enabled
  • The esbuild loader for this file is currently set to "js" but it must be set to "jsx" to be able to parse JSX syntax.

Cause 1 of 4

A source file reached by the crawl does not parse

You seeBelow the entry list: a parse error with a path inside src and a line number

Check

Failed to scan for dependencies from entries is a header Vite puts in front of the parser error from a file the crawl reached, so the useful part is what comes after the list of entries. Filter the output down to that part and open the file it points at.

Check
npx vite --force 2>&1 | grep -A 12 "Failed to scan"

Fix

Repair the code at that position, for example a leftover merge marker, an unclosed bracket or an import line typed only halfway. Start Vite again after each repair, because a second file may fail once the first one parses.

Fix
npx vite --force

Verify

The server prints its local URL, and with the deps log on the crawl ends with a line that reports the scan as completed and lists what it found.

Verify
npx vite --debug deps

Confirmed by github.com

Did this fix it?

Cause 2 of 4

JSX is written inside a file that ends in .js

You seeThe JSX syntax extension is not currently enabled (Vite 7, where esbuild runs the crawl)

Check

On Vite 7 the scan fails with The JSX syntax extension is not currently enabled when JSX sits in a .js file, because the crawl runs through esbuild, whose .js loader reads plain JavaScript only. Vite handles JSX in .jsx and .tsx files without setup. List .js files under src that contain component tags.

Check
grep -rlE "<[A-Z][A-Za-z]*[ />]" src --include=*.js

Fix

Give every file that holds JSX the .jsx extension, then update the imports and the script tag in index.html that still name the old file. No config change is needed after that.

Fix
git mv src/main.js src/main.jsx
git mv src/App.js src/App.jsx
# index.html: <script type="module" src="/src/main.jsx"></script>

Verify

Start the server with --force once more. The JSX message no longer appears, and the page loads.

Verify
npx vite --force

Confirmed by esbuild.github.io

Did this fix it?

Cause 3 of 4

The crawl includes HTML pages that are not part of the app

You seeThe entry list names .html files from places like a docs folder, a copied template or an old output folder

Check

The scan can also fail inside an HTML page that is not part of your app, because without optimizeDeps.entries Vite globs every .html file under the project root. Only node_modules, the current build.outDir, __tests__ and coverage are left out, so an old build folder with another name or a static demo page with a module script is crawled too.

Check
find . -name "*.html" -not -path "*/node_modules/*"

Fix

Name the real entry points yourself. The patterns are globs relative to the project root, and once they are set Vite stops searching for HTML files on its own. Deleting the leftover folder also works.

Fix
// vite.config.js
import { defineConfig } from 'vite'

export default defineConfig({
  optimizeDeps: {
    entries: ['index.html'],
  },
})

Verify

Run with the deps log again. The entry list now holds only what you configured.

Verify
npx vite --force --debug deps

Confirmed by vite.dev

Did this fix it?

Cause 4 of 4

A Vue or Svelte script block holds TypeScript but has no lang attribute

You seeThe parse error points at a .vue or .svelte file, with ?id= and a number after the file name

Check

In Vue and Svelte projects the scan fails on a script block that holds TypeScript but has no lang="ts", because the scanner picks the parser for each block from that attribute and reads the rest as JavaScript. Look for script tags that lack the attribute.

Check
grep -rn "<script" src --include=*.vue --include=*.svelte | grep -v "lang="

Fix

Add lang="ts" to every script block that uses TypeScript syntax, or take the type annotations out of blocks that are meant to stay JavaScript.

Fix
<script setup lang="ts">
const count: number = 0
</script>

Verify

Restart with --force and confirm the component renders.

Verify
npx vite --force

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Name every React component file .jsx or .tsx from the first commit.
  • Set optimizeDeps.entries to ['index.html'] in repositories that also hold docs, demos or old build folders.
  • Run npx vite build in CI on each pull request, so a file that does not parse fails there before anyone pulls it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.