Skip to content

dev server: fail the importers of a file that was not there to read - #46983

Closed
robobun wants to merge 9 commits into
mainfrom
robobun/2d8d0266/dev-server-missing-file-importers
Closed

robobun wants to merge 9 commits into
mainfrom
robobun/2d8d0266/dev-server-missing-file-importers

Conversation

@robobun

@robobun robobun commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • A dev server build can resolve an import to a file that is gone before the read. The build passes. The page lacks the module or throws Failed to load bundled module '...'. This is not a dynamic import, and therefore is a bug in Bun's bundler.
  • src/runtime/bake/dev_server/failures.rs:336 leaves the error to the importers that it builds again. An import that this build already resolved gets none.

Fix

  • After the parse, missing_sources::report fails each importer of a missing file with Could not resolve, and watches for the file.
  • The watch asks the file system and bundles no file change under node_modules: the resolver keeps a directory that was away as not found.
  • Correct: the pass resolves nothing and calls no plugin, so the build ends.
  • Verified: 38 new tests in test/bake/dev/{bundle,css,html}.test.ts (35 fail on main), test/bake/. Self-reviewed: 52 concerns raised, 48 addressed.

Background

  • Every import of a path shares one source, also when its read fails.
  • Considered: resolve those imports again (a plugin can loop it), or list directories again per build (13 opens per reload).

Downsides

Notes

Origin. Found by tests of #46648, not by a user. #22686 ends in this state too (#44690 owns it). No user reported the package orders below, and no issue tracks them.

What main does, with no plugin. Release builds, main is 449877f.

  • A file is renamed in a project directory before a build reads it. The page of the route that imports it throws the error above, also after a save of the importer. This change shows Could not resolve: "./src/renamed". The first build after the next change in that directory finds the new file.
  • The one importer of a barrel (a sideEffects: false package entry) is saved while the barrel is away. Main prints Reloaded, and the page throws Failed to load bundled module 'node_modules/named/a.js'.
  • A second route imports a barrel that was deleted. Main answers 500, 200, 200, and the page of request 2 has no module of the package. This change answers 500, 500, 500.
  • A deleted @imported stylesheet: main prints Reloaded and drops the rules with no error. A deleted image under an open page is an error on main in some runs only. Both are always an error now.
  • Build 367d939 answers the second-route case with 500, 500, 500. That is not a regression of Hardening: fix crashes across the runtime, bundler, dev server, shell and CLI #46021. Before it, check_route_failures read the failures of the last build, also when the route does not reach them, and first.ts had failed. Hardening: fix crashes across the runtime, bundler, dev server, shell and CLI #46021 reads the failures that the route reaches. The import of second.ts has none on record.
  • The other new tests order two reads with an onLoad plugin, or use an onResolve plugin. They cover the two arrival orders of the first report, two graphs of one file, and a file that is back in the same build.

How it works

  • note runs in the error arm of on_parse_task_complete when handle_parse_task_failure returns true (ENOENT, FileNotFound, ModuleNotFound). It removes the path from a path map only when the map gives that source. The four other callers of handle_parse_task_failure have no source, or pass Plugin or InvalidCssImport.
  • on_file_deleted no longer removes the path from the path map of every target. That loop also removed the live copy of another graph. note is now the only place that removes an entry, and PathToSourceIndexMap::remove is pub(crate).
  • report runs in on_after_decrement_scan_counter when is_done() is true and a source was noted, before finish_from_bake_dev_server.
  • A record that holds a source index is bound when that source was noted. A record that holds only a path is bound when the file was found missing on its side (client, or server and SSR), its text is the path, and its pretty is a module id. resolve_import_records sets pretty where it binds a record to a module, also for a module that the dev server kept from an earlier build. The record of an external import has pretty == text.
  • A bound record is not an error when its module has a source again: a source with the same pretty, in a path map of the same side. process_resolve_queue files a source under the target of its importer, so the map of the server target can hold the SSR copy of a path. Graph::source_of_module compares the id for that reason.
  • A reported record goes back to its specifier, as a record that did not resolve. The importer loses its parts, as a file whose first resolve failed. A record with HANDLES_IMPORT_ERRORS (a require() in a try block) is not an error: the require() throws Cannot require module ./x, as for a file that never existed.
  • The watch is for the path of the missing file, not for the specifier: DirectoryWatchStore::track_missing_file. A plugin or an old directory listing can resolve the specifier while the file is missing. With the specifier, each change in the directory of the importer built it again.
  • The retry of that dependency is one bun_sys::exists call (Dep.is_file, hot_reload_event.rs:118). A resolve of the path made the resolver keep a directory that is gone as not found.
  • DirectoryWatchStore::insert no longer asks the resolver for the directory. The lookup was there to reuse a directory descriptor for kqueue, and no dev server resolver stores one (store_fd is false, resolver.rs:1006, :4908). For a directory that is gone it stored a not-found entry, and nothing drops that entry for a package specifier. Where the watcher needs a descriptor the store opens its own, as it already did, so Entry.dir_fd_owned is gone.
  • process_file_list drops the file names that the Linux watcher gives for a directory under node_modules, once the store placed a watch there (watched_node_modules, hot_reload_event.rs:163). Three gates keep node_modules out of the watch list (bundle_v2.rs:5775, Watcher.rs:787, :970), and the watch of a failed import passes none of them. With the names, the removal of a package built its files while the package was away.
  • track_resolution_failure is #[inline(never)]: it is now a short gate in front of the shared track, and inlined it changed resolve_import_records.
  • The error text is in missing_sources::log_missing_file: Could not resolve: "x", with Maybe you need to "bun install"? for a package specifier, and the note File not found "<path>". It repeats two format strings of resolve_import_records. A shared function for that block conflicts with bundler: name the right target when a non-bun build imports a Bun builtin #42036, resolver: match file name case the way the directory's filesystem does #44690, bundler: derive the options of a server build's page from the browser target #46548 and bundler: warn and keep require.resolve() of a missing package instead of failing the build #46632, which edit it. The copy does not have the rule of that block for an HTML path under the project root, which prints the path from the root.

Other answers that change

  • A stylesheet whose @import is missing fails. If the page links it, no update is sent and the page keeps its rules. If another stylesheet imports it, the update has none of its rules until the file is back. Main dropped only the rules of the missing file. An @import that never resolved already does this on main.
  • A script with a kept module of a file fails when another file of its side reads the file in the same build and does not find it (a script and a stylesheet that use one image). On main this depends on which of the two is read first.
  • A script imports a stylesheet through a specifier that an onResolve plugin answers. The stylesheet names, by url() or @import, a path that a plugin answers and whose file is missing. Main builds without the file and keeps the stylesheet (4 of 4 forms). This change answers 500 once, then 200 with no <link> to the stylesheet, also after the file is there (4 of 4). Main has the same loss when the name does not resolve at all: a stylesheet that fails in its first build loses the edge from its importer (dev server: mark a failed stylesheet under an html or script import as a css root #47062). When the html file links the stylesheet, there is no loss (4 of 4).

A package that goes away. Debug builds, Linux x64, the statuses of the page requests in order. main is 9fe1cd6. before is c6c92f5 merged with main f7607a3.

# Order main before now
1 one save while the package is away, package back, save 200 200 200 200 500 500 200 200 200
2 barrel deleted, save, package removed and put back, save 200 200 200 200 500 500 200 200 200
3 row 1 with one request while the package is away 200 200 200 200 200 500 500 500 200 500 500 500
4 two saves while the package is away 200 500 200 500 200 500
5 two importers, one save while the package is away 200 500 200 500 200 500
6 row 2, then: barrel deleted, save, request, barrel back, request, save, request 200 200 200 200 200 200 500 500 500 500 200 200 500 500 500
  • Rows 1 and 2 were the two writers that this change had: the lookup in insert, and the resolve in the retry. With a nested and a hoisted copy of a package, before served the hoisted copy after row 1. Main and now serve the nested one.
  • Row 3 is worse than main. A failed page is built again at each request (BUN_ASSUME_PERFECT_INCREMENTAL=0, the default of a release build). That build resolves the package while its directory is away, and the resolver keeps the directory as not found. Nothing asks again for a package specifier. Main builds nothing at that request, because its build of the save passed. Main reaches the same state in rows 4 and 5, and for a package that is installed after its first import. Resolver: run a missed lookup once more at a fresh Generation, with DirInfo and not-found marks under Generation #40279 is the open change for the resolver.
  • Row 3 with a plugin whose name contains tailwind and <link rel="stylesheet" href="./styles.css">, for a stylesheet that imports a file of the package: 200, 500, then 200 with no <link> at each request (main: 200 with the link four times). A review run of merged trees, not repeated here, had the link back only with dev server: mark a failed stylesheet under an html or script import as a css root #47062 and Resolver: run a missed lookup once more at a fresh Generation, with DirInfo and not-found marks under Generation #40279 together.
  • Row 6 is worse than main. When a watched directory is removed and made again, the store keeps its entry and the watch of the old directory is dead (insert returns at found_existing). The next missing file there gets no live watch, and the request caches a listing without the file. The same steps with no removal before them end at 200, 500, 200, 200. The dead entry is on main for any watched directory. dev server: release the directory watch of a failed import by hash #46916 rewrites that bookkeeping.
  • A stylesheet reads each file that it names at every build (bundle_v2.rs:7088), a barrel is parsed again when a build asks for an export that no build loaded (bundle.rs:88), and a stylesheet under a tailwind plugin is built again at each save (hot_reload_event.rs:201). These are the reads that meet a package that is away.

Not fixed here

  • Rows 3 and 6 of the table above, and the stylesheet that a script imports through an onResolve plugin.
  • A dependency of the watch store stays when its importer builds again without the failed import (on main, directory_watch_store.rs:13). With this change such a dependency can keep a watch on a package directory. The removal of that package then builds nothing (test ... while the watch of an earlier failed import is left builds nothing).
  • On macOS and FreeBSD the store and the watcher each close the descriptor of a directory watch (directory_watch_store.rs:79, Watcher.rs:436). The later close can hit a descriptor that was opened in between. Main does this for each failed relative import that resolves, and it is not changed here. This change places watches where main placed none (a package file that was missing, an import that stayed bound), so it adds places that reach it. Read from the code, not run: no macOS machine here. dev server: release the directory watch of a failed import by hash #46916 is the open change for it: its store holds no descriptor, and it has a test for this case.
  • A route's own file that is missing (bake: report a missing root file as a build failure instead of running the route #42865, which conflicts with main today). The source is noted, and no import record names it.
  • A module that moved: a rename, a new main, an upgrade in an isolated store. 20 sequences change a package on disk: 15 before the first build of the importer, 5 in a symlinked package after it. In the 5 that delete a file and write it back, the page has the new module at the first or second request after the write (main: 4 have no module until the importer is saved). In the 13 that move the module, the resolver keeps the old listing and the error stays. For 4 of them it ends at the next change in the directory of the old file. The 9 through a symlink need a restart (resolver: bust the real-path alias of a symlinked directory with the dir cache #40587, dev server: follow a retargeted symlink on the import path #41539). On main 9 of the 13 end at a page without the module and 4 at the old module. With dev server: read a directory again when a file that no build bundled fails to open #46846 merged, 4 of the 13 find the module at the next request.
  • A script and a stylesheet that reach one file through two paths (a symlink) are two files for the pass.
  • A request that arrives while a directory watch builds the importer again can get a script bundle without the importer. Main has this race for an import of a file that is created (7 of 10 runs). The watch of this change reaches it in a restore sequence (6 of 10).
  • A deleted @import: a page load can be answered 200 without the rules of the deleted file before the error. A run in review, of this change merged onto 9fe1cd6, had this in 6 of 100 rounds with one load every 10 ms. All 100 rounds then answer 500. From the code, not from a run of this build: insert_failure (incremental_graph.rs:1538, not changed here) drops the asset of a stylesheet that fails, inside finalize_bundle. By that reading, a page that was answered just before gets 404 for the whole stylesheet.
  • An importer that does not resolve as an entry point, or that is a module of a plugin namespace, is not built again when its import is deleted (bundle_v2.rs:3068, :3078). A page above it keeps the old modules.
  • A module of a plugin namespace that onLoad declines. The server copy and the SSR copy of one path under one map key, with all files on disk. An HTML file and its script that change in one build (Saving the <script> modules in HTML causes "Failed to load bundled module" error #20877, dev server: store the path of a failed stylesheet in its import record #42741). A route that reaches a failure of an earlier build (dev server: fail a route that reaches a recorded build failure #46801). The requests of a barrel (dev server: keep a barrel's requests across builds, or never defer it again #46648).
  • The existing test removing 'use client' from a component with a pending resolution failure still prints the error above, on main and with this change.
  • On Windows, a file that is being deleted can read as EPERM. That is not one of the three error names, so it keeps the error of main.
  • "One error, then 200 on the next request" needs BUN_ASSUME_PERFECT_INCREMENTAL=0, the default of a release build.

Other designs that were built or measured

  • Resolve the bound imports again when the scan is done. A plugin can return a new missing path for each call, so the scan can start again without end.
  • Advance the resolver generation for each dev server bundle, so each bundle lists directories again. Per hot reload of a route with 13 directories: 13 directory openat and 26 getdents64 (main: 0 and 0). It does not fix the plugin path, the delete before the read, or the two graphs. bundler: advance the resolver generation once per build instead of once per queue drain #38212 is not changed.
  • Record a failure for the missing file in handle_parse_task_failure, as a userland onLoad plugin that throws can do today. The missing path then owns the failure: the importer that is already bound is still bundled, and a require() in a try block becomes a build error.

Order with open PRs

Measurements. Release builds, Linux x64. Tools: size, nm, llvm-objdump, gdb. Not installed here: bloaty, perf, valgrind, strace.

The whole change, main f7607a3 to this head:

  • .text: 108,798,697 to 108,803,817 B (+5,120). Stripped binary: 138,270,840 to 138,274,936 B (+4,096).
  • 20 named functions differ, net +6,591 B (nm -S). The largest: report 4,302 B, track 2,823 B (track_resolution_failure 2,906 to 96 B), a reserve_rehash of the path table 1,430 B, note 731 B, source_of_module 422 B.
  • Test time, median of 3 interleaved runs: bundle.test.ts 19.7 to 38.3 s (54 to 88 tests), css.test.ts 12.0 to 12.9 s, html.test.ts 5.2 to 5.9 s.

The pass (missing_sources), main 449877f to c6c92f5:

  • .text: 82,164,617 to 82,168,969 B (+4,352). File: 107,730,656 to 107,734,752 B.
  • New: report 4,286 B, note 731 B, Graph::source_of_module 422 B. on_parse_task_complete: 18,138 to 18,203 B. BundleV2::init: 13,387 to 13,419 B. handle_parse_task_failure: 3,319 to 3,125 B.
  • Same instruction lists as main: resolve_import_records (2,885), process_resolve_queue (485), is_done (79), and the success path of on_parse_task_complete. Only address immediates differ.
  • With no missing file, note, report and source_of_module run 0 times: a dev route of 72 modules with 2 saves and an idle request, a bun build of 401 modules, a dev bundle with a syntax error.
  • BundleV2::init: 816 to 820 instructions for bun build, 823 to 827 for a dev server bundle (the new Vec). BundleV2 is 2,232 to 2,256 B. A dev server bundle runs 2 more (cmp, jne) when the scan is done.
  • The report pass with 200 imports: 44,357 instructions for 1 missing file, 415,832 for 50, 876,872 for 100.
  • bun build: the error output of 8 fixtures and the output of a 401 module build are byte-identical to main.
  • The first report as a timing repro, 24 interleaved runs: main serves 10 pages with no module of one package and no error. This change serves 0: 11 runs answer 200 with both packages, and 13 report the error and answer 200 at the next request.

The watch store and the node_modules rule (the last two commits). before is c6c92f5 merged with main f7607a3:

  • .text: 108,803,561 to 108,803,817 B (+256). The stripped binary has the same size. 9 named functions differ, net +217 B: track_resolution_failure 2,900 to 96 B with the new track 2,823 B, process_file_list 5,241 to 5,392 B, free_entry 372 to 316 B, report 4,270 to 4,302 B.
  • Same instruction lists as before: resolve_import_records (2,757), run_resolver (937), process_resolve_queue (497), on_parse_task_complete (3,327), dir_info_cached_maybe_log (203), missing_sources::note (181). start_async_bundle, finish_from_bake_dev_server and the watcher callback differ only in field offsets.
  • DevServer grows by 8 B (the flag). Dep: 40 to 48 B, one for each failed import under a directory watch. Entry: 16 to 12 B. By a scratch size_of constant that is not committed: the debug build has no type information for gdb ptype.
  • A healthy save, counted by single steps in gdb: the watcher callback runs 649 instructions before and now. process_file_list runs 758, 535 and 572 before, and 762, 539 and 576 now (+4 for each call).
  • A healthy save and a healthy request, by the debug logs: 0 calls of insert, 0 directory opens of the resolver, 0 evictions, before and now.
  • Syscalls of the dev server thread on the package directory (gdb catch syscall, debug build). The save that finds the barrel missing: openat 3 to 1, getdents64 2 to 0. The same with the directory gone: failing openat 2 to 1. A change in the watched directory with one pending dependency: openat 4 to 0, getdents64 4 to 0, failing access 0 to 2. The removal of the watched directory: failing openat 4 to 0, failing access 0 to 2.
  • A failed relative import into a directory that the resolver has: 3 opens and 1 readdir, before and now.
  • Descriptors and inotify watches (procfs, debug build): 20 directory watches add 40 descriptors and 20 watches, before and now. 20 rounds of a package away and back add none. macOS not run: the lookup gave no descriptor there (resolver.rs:1006), so the store already opened its own.

Tests

  • 38 new tests. On main 35 fail. Two pass on main and hold new code: the SSR row of "a file that is back ..." and "a barrel that is back ...". "deleting the image of an image tag ..." fails on main in some runs.
  • 19 mutations of the pass (each clause of missing_sources.rs, source_of_module, the loop of on_file_deleted, the watch rule, the call of note): each fails at least one test.
  • 8 mutations of the last two commits (the lookup back, the retry by a resolve, a dependency that is not marked as a file at each of its two sites, the flag never set, the names not dropped, and the two below). 6 fail at least one of the 8 package tests. No test fails for two: the kind of a dependency in the dedupe key of insert, and the absolute-path guards of track_missing_file.
  • The 8 package tests all fail on before. Two of them pass with only the lookup deleted and the resolve kept, and fail without the node_modules rule.
  • Debug build at this head: the three files, 125 of 125. 25 more files of test/bake/, test/bake/dev/ and bun-serve-html*.test.ts: 204 pass, 2 skip. The release build: 125 of 125.
  • At c6c92f5, not run again: 19 files of test/bundler/, test/bundler/esbuild/ and resolve errors, 1,119 pass. Two tests of production.test.ts and three --compile tests of cli.test.ts need --timeout on a debug build here.
  • test/internal/source-lints/: 190 of 194 pass, and 4 that this change does not touch pass with a longer --timeout on the debug build. cargo clippy -p bun_bundler -p bun_runtime: no new warning. bun run rust:check-all for x86_64-pc-windows-msvc, aarch64-apple-darwin and x86_64-unknown-freebsd.
  • Platforms: four tests delete a watched file with dev.delete and skip win32, as the two tests of main that do the same. The 8 package tests have no platform skip. On the lanes of 886f53e (build 135849) the three files pass at the first attempt on Linux, Windows 2019 x64, Windows 11 aarch64, macOS aarch64 and macOS x64. bundle.test.ts there: 84 pass and 4 skip on each Windows lane, 87 pass and 1 skip on each macOS lane (a skip of main). Nothing ran on a Windows or macOS machine here.

Self-review. Two reviews, 34 and 18 concerns. Not done of the first: a route's own missing file is not failed here (named above). Both arrival orders of the first report stay as tests, because the report asks for each order. One sequence of #46944 that the review described did not reproduce on main with this change: six deleted-barrel sequences end at the right page. Not done of the second, which read the last two commits: a test for each of the two clauses named under Tests. That review asked for the node_modules rule, and it left rows 3 and 6 to the resolver (#40279) and to the store bookkeeping (#46916).

A parse task of the dev server can find that its file is gone. The dev
server records no failure for the file, because the files that import it
report it when they resolve the import again. An import record that the
build bound to the file before the task failed does not resolve again.
The build passed, and the page failed when it loaded:
"Failed to load bundled module '...'. This is not a dynamic import, and
therefore is a bug in Bun's bundler."

The bundler now keeps the sources whose file was not there to read.
When the scan of a dev server build is done, it fails each file of the
same side (client or server) that still names a module of such a file,
with the error of an import that does not resolve. A record whose module
has a source again is not an error.

The watch for such an import is for the file, not for the specifier: a
plugin or an old directory listing can resolve the specifier while the
file is missing.

`on_file_deleted` no longer removes the path from the path map of each
target. The pass removes the entry of the source that failed, so the
copy of another graph keeps its entry.
@robobun

robobun commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status of #46983

  • Reproduced on main (449877f, release build) with bun test test/bake/dev/bundle.test.ts -t "saving the importer of a barrel": the build passes, and the page throws Failed to load bundled module 'node_modules/named/a.js'. This is not a dynamic import, and therefore is a bug in Bun's bundler. 35 of the 38 new tests fail on main.
  • With this change (886f53e), bun bd test test/bake/dev/bundle.test.ts test/bake/dev/css.test.ts test/bake/dev/html.test.ts passes 125 of 125.
  • The 500 for a package that was away for one save is gone at 886f53e. Repro on c6c92f5: a page imports lib. Rename node_modules/lib away, save the page, rename the directory back, save the page again. The error stays. At 886f53e the second save finds the package, as on main. 8 new tests cover the package orders, and all 8 fail on c6c92f5.
  • CI on 886f53e (build 135849): the three test files pass at the first attempt on Linux, Windows 2019 x64, Windows 11 aarch64, macOS aarch64 and macOS x64. 4 of the new tests skip win32: they delete a watched file with dev.delete.
  • Two tests are red in that build, and this change touches neither. test/aot/engine/ir-6.test.ts fails on five lanes, and it is also red on main (build 135526). vendor/elysia/test/response/stream.test.ts fails on debian 13 x64-asan. No other test failed at every attempt. Main is still at the commit that this branch has (f7607a3), so a new run would show the same ir-6 failure.

@robobun

robobun commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 11:30 AM PT - Oct 30th, 2026

❌ @robobun, your commit 886f53e has 2 failures in Build #135849 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 46983

That installs a local version of the PR into your bun-46983 executable, so you can run:

bun-46983 --bun

On both Windows lanes, seven new tests of framework builds fail in each
attempt. Their onLoad plugin deletes a file before the bundler reads it.
On Windows the build still reads the file: the build of the barrel tests
passes, and in the late.ts tests the onLoad of second.ts has no path to
write ("path must be a string or a file descriptor"). The 19 other new
tests that have no skip pass on Windows.
Comment thread src/bundler/Graph.rs Resolved
Comment thread src/bundler/missing_sources.rs Resolved
Comment thread src/bundler/missing_sources.rs Resolved
Comment thread src/runtime/bake/dev_server/failures.rs Resolved
@robobun
robobun marked this pull request as ready for review October 26, 2026 13:29
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b68e2c0 and 8182c52.

Files selected for processing: 1
  • test/bake/dev/bundle.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

The dev server records missing files during bundle processing, matches affected imports to those sources, and reports unresolved imports. Resolution tracking includes absolute JavaScript and TypeScript specifiers. New tests cover missing-file errors, assets, and recovery after files return.

Changes

Missing-source handling

Layer / File(s) Summary
Capture missing sources across build graphs
src/bundler/Graph.rs, src/bundler/PathToSourceIndexMap.rs, src/bundler/bundle_v2.rs, src/bundler/lib.rs, src/runtime/bake/dev_server/failures.rs, src/runtime/bake/dev_server/incremental_graph.rs
Parse-failure handling returns whether a file is missing. BundleV2 records missing source indices and targets, then reports them after asynchronous bundle completion. Graph lookup checks target and path. File deletion no longer removes cached path-to-source entries.
Reconcile imports and report failures
src/bundler/missing_sources.rs, src/runtime/bake/dev_server/directory_watch_store.rs
Missing-source reporting matches records to importer rows, updates records when sources return, and marks unresolved imports disabled. Resolution tracking accepts absolute specifiers for JavaScript and TypeScript loaders.
Test missing-source errors and recovery
test/bake/dev/bundle.test.ts, test/bake/dev/css.test.ts, test/bake/dev/html.test.ts
Tests cover plugin-resolved paths, stylesheets, HTML assets, graph boundaries, and recovery.

Suggested reviewers: jarred-sumner, alii

Priority: Normal

Merge Risk: Minimal · up to 8182c

No actionable merge-blocking risk remains established for this change.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: the dev server now fails importers when a source file was unavailable during reading.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description clearly explains what the PR changes, why it is needed, known limitations, performance impact, and how it was verified with tests and checks. It does not use the template headings exac…
Full details: Description check

Explanation

The description clearly explains what the PR changes, why it is needed, known limitations, performance impact, and how it was verified with tests and checks. It does not use the template headings exactly, but it contains the required information under equivalent sections.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I also checked the four other handle_parse_task_failure call sites in src/bundler/bundle_v2.rs (entry-point resolve, plugin, invalid CSS import, too-deep) — none has a parsed source index to note, so skipping missing_sources::note there is consistent; and the removed path-map loop in on_file_deleted was only reachable from failures.rs:339/342, which the new conditional removal in note() covers.

Extended reasoning...

The change adds a dev-server-only pass (src/bundler/missing_sources.rs) that rewrites import records bound to a source whose file was missing at read time, widens handle_parse_task_failure to return a bool, and drops the unconditional path-map removal from on_file_deleted; it touches no auth, crypto, or injection surface. The ruled-out note covers sibling call sites and the deleted removal loop so a human reviewer can focus on the posted finding and the SSR/server-components rebinding logic.

Comment thread src/bundler/missing_sources.rs Resolved
On macOS the write to the file that was renamed is not a change of its
directory for the watcher, so the test waited for the dev server until
its timeout. A new file in the directory is a change on each platform.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I also checked whether handle_parse_task_failure returning true for ModuleNotFound could make note() record an importer whose own import failed to resolve (which would cascade a Could not resolve error onto every file importing it) — it cannot: a resolve-step failure sets process_log = false in on_parse_task_complete, so that path never reaches handle_parse_task_failure or note(). I also confirmed the absolute path handed to track_resolution_failure is honored: join_abs_string_buf resets the base on an absolute part, so the watch lands on the missing file's own directory rather than the importer's.

Extended reasoning...

The change adds a crate-private missing_sources pass to the Bake dev server bundler, with unsafe set_len(0) / drop_in_place on graph rows mirroring the existing failed-file pattern in run_resolution_for_parse_task, a bool return added to handle_parse_task_failure, and ~1,000 lines of new dev-server tests; no security-sensitive surface. The only new commit since the prior review is a test-only tweak, and one inline finding is already being posted, so this note only records the two extra concerns examined and ruled out.

Comment thread test/bake/dev/bundle.test.ts Resolved
A batch of the test harness that bundles nothing waits 500 ms and
prints "WARN: Dev Server did not pick up any changed files". Two of
the new tests did that on each run.

The rename test now saves the importer in the batch that adds a file
to src/, so the batch bundles. The plugin test writes the unrelated
file inside expectNoWebSocketActivity, which also fails the test when
that change builds the importer again.
Comment thread test/bake/dev/bundle.test.ts Resolved
The filter of the two "loads last" tests was /second\\.ts$/ in the
plugin file. It matches no path, so neither test deferred a file. The
plugin now records the order of the two loads, and the test asserts
that order.

Three filters of framework tests matched "/" only. On Windows their
plugins did nothing, and eight tests skipped win32 for the failures
that followed. The filters now match both separators, and the skips
are gone.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@robobun

robobun commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

#47016 is stacked on this branch. It adds the case that the body lists under "Not fixed here": an importer that does not resolve as an entry point.

One finding from that work applies to this PR alone:

  • report_importer gives track_resolution_failure the path of the missing file. For a removed package, the directory of that file is gone. DirectoryWatchStore::insert calls read_dir_info for it, the resolver caches the directory as not found, and no watch is placed.
  • A package specifier never makes the resolver look again. The import stays at Could not resolve after the package is back and the importer is saved. Main finds the package at that save.
  • Repro on c6c92f5: a page imports lib. Rename node_modules/lib away, save the page (the error shows), rename the directory back, save the page again. The error stays.
  • Only macOS and FreeBSD read the result of that lookup (REQUIRES_FILE_DESCRIPTORS), and dev server: release the directory watch of a failed import by hash #46916 deletes the lookup. A release build of this PR with the lookup skipped answers 200 in the repro above, like main. That build is a patched binary, not a compiled change.
  • dev server: continue the deleted-file walk through importers that are gone #47016 (42ca0b1) does not change DirectoryWatchStore::insert any more. It drops the directories that the resolver has as not found at the end of missing_sources::report, and it has tests for the flow (a removed package that is back builds at the next save). So this PR alone still has the 500. Merge it together with dev server: continue the deleted-file walk through importers that are gone #47016, or remove the lookup here.

DirectoryWatchStore::insert asked the resolver for the directory only
to reuse a descriptor, and no dev server resolver stores one. For a
directory that is gone, that lookup kept the directory as not found,
and nothing asks again for a package specifier. One save while a
package was away then failed its import until a restart.

The store now opens its own descriptor where the watcher needs one. A
dependency for a missing file is retried with one exists() call. A
resolve there kept the same entry when the watched directory went away.
…dules

The dev server does not watch node_modules. The watch that the
directory watch store places for a failed import is the one watch that
can be there. On Linux the watcher names each file that changes in a
watched directory, and the dev server built those files. When a package
was removed, that build resolved its importers while the package was
away, and the resolver kept the directory as not found.

The store now records that it placed a watch under node_modules. From
then on process_file_list drops the file names that the watcher gives
for a directory there. The directory event still retries the failed
imports of that directory.

track_missing_file joins the path as track_resolution_failure does, so
the watch has the directory name that the watcher reports.
track_resolution_failure stays out of line, so resolve_import_records
has the same code as before.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-30.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant