Repository navigation
Conversation
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.
|
Status of #46983
|
|
Updated 11:30 AM PT - Oct 30th, 2026
❌ @robobun, your commit 886f53e has 2 failures in
🧪 To try this PR locally: bunx bun-pr 46983That installs a local version of the PR into your 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.
|
No actionable comments were generated in the recent review.
|
| 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:
Merge Risk: 
Minimal · up to 8182c
-
No actionable merge-blocking risk remains established for this change.
Pre-merge checks: 
4
-
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.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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.
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.
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.
|
#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:
|
…server-missing-file-importers
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.
|
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. |
Problem
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:336leaves the error to the importers that it builds again. An import that this build already resolved gets none.Fix
missing_sources::reportfails each importer of a missing file withCould not resolve, and watches for the file.node_modules: the resolver keeps a directory that was away as not found.test/bake/dev/{bundle,css,html}.test.ts(35 fail on main),test/bake/. Self-reviewed: 52 concerns raised, 48 addressed.Background
Downsides
import()that never runs..textgrows by 5,120 B. A bundle runs 4 to 6 more instructions, a hot reload event 4.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.
Could not resolve: "./src/renamed". The first build after the next change in that directory finds the new file.sideEffects: falsepackage entry) is saved while the barrel is away. Main printsReloaded, and the page throwsFailed to load bundled module 'node_modules/named/a.js'.@imported stylesheet: main printsReloadedand 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.check_route_failuresread 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.onLoadplugin, or use anonResolveplugin. 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
noteruns in the error arm ofon_parse_task_completewhenhandle_parse_task_failurereturnstrue(ENOENT,FileNotFound,ModuleNotFound). It removes the path from a path map only when the map gives that source. The four other callers ofhandle_parse_task_failurehave no source, or passPluginorInvalidCssImport.on_file_deletedno longer removes the path from the path map of every target. That loop also removed the live copy of another graph.noteis now the only place that removes an entry, andPathToSourceIndexMap::removeispub(crate).reportruns inon_after_decrement_scan_counterwhenis_done()is true and a source was noted, beforefinish_from_bake_dev_server.prettyis a module id.resolve_import_recordssetsprettywhere 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 haspretty == text.pretty, in a path map of the same side.process_resolve_queuefiles 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_modulecompares the id for that reason.HANDLES_IMPORT_ERRORS(arequire()in atryblock) is not an error: therequire()throwsCannot require module ./x, as for a file that never existed.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.bun_sys::existscall (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::insertno 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_fdis 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, soEntry.dir_fd_ownedis gone.process_file_listdrops the file names that the Linux watcher gives for a directory undernode_modules, once the store placed a watch there (watched_node_modules,hot_reload_event.rs:163). Three gates keepnode_modulesout 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_failureis#[inline(never)]: it is now a short gate in front of the sharedtrack, and inlined it changedresolve_import_records.missing_sources::log_missing_file:Could not resolve: "x", withMaybe you need to "bun install"?for a package specifier, and the noteFile not found "<path>". It repeats two format strings ofresolve_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
@importis 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@importthat never resolved already does this on main.onResolveplugin answers. The stylesheet names, byurl()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.
mainis 9fe1cd6.beforeis c6c92f5 merged with main f7607a3.insert, and the resolve in the retry. With a nested and a hoisted copy of a package,beforeserved the hoisted copy after row 1. Main andnowserve the nested one.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.tailwindand<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.insertreturns atfound_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.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 atailwindplugin 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
onResolveplugin.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).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.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.@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, insidefinalize_bundle. By that reading, a page that was answered just before gets 404 for the whole stylesheet.bundle_v2.rs:3068,:3078). A page above it keeps the old modules.onLoaddeclines. 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).removing 'use client' from a component with a pending resolution failurestill prints the error above, on main and with this change.EPERM. That is not one of the three error names, so it keeps the error of main.BUN_ASSUME_PERFECT_INCREMENTAL=0, the default of a release build.Other designs that were built or measured
openatand 26getdents64(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.handle_parse_task_failure, as a userlandonLoadplugin that throws can do today. The missing path then owns the failure: the importer that is already bound is still bundled, and arequire()in atryblock becomes a build error.Order with open PRs
forget_missing_dirs. A review run, not repeated here, had that function still heal row 5.git merge-treeof its head (be8a64c) with this head is clean, and its 8 tests still fail on this head alone. The two were not built together.DirectoryWatchStoreand deletes the same lookup. It also ends the double close of the watch descriptor on macOS and FreeBSD, so after it this change adds no place that reaches that. It conflicts with main today. The PR that lands second takes the other'sinsertandEntry.Depfor the resolver retry, andDep.is_filefills the same slot. Both conflict with main today. The PR that lands second makes one retry kind of the two fields.git merge-treeof its head (c1808dd) with this head conflicts in one hunk ofsrc/bundler/bundle_v2.rs, at the parse failure site. The two were not built together here.git merge-treeis clean. On the merged tree 118 of 119 tests of the three files pass. Its testfinds a module that moved before any build read itexpects["EXPORT_A"]after the first save. With both changes that save shows the error, and the next request already has the module. The PR that lands second changes that assertion.bundle.test.ts:2108). That build now fails withCould not resolve. The PR that lands second changes that assertion.prettytest ofis_boundto that flag.css.test.ts.node_modulespath component, not by the letters #46809, dev server: bundle a saved text, json or file module through its importers #46878, dev server: a page keeps a barrel that a build only bundled again #46879, bake: do not demote a client component boundary when the SSR graph imports it #46901. These conflict with main today, so their state with this change is not known: bundler: print import.meta.main per chunk when a build has several entry points #41235, dev server: fail a loaded route when a build error is below its client entry point #42841, resolver: do not cache an EMFILE, and fail the resolution that had one #44540, resolver: match file name case the way the directory's filesystem does #44690, bundler: resume the shared resolve pass for imports that went to onResolve plugins #45408, dev server: keep one import record for each import statement #46742, dev server: fail a route that reaches a recorded build failure #46801, resolver: re-check a cached "not found" once the directory is known to exist #46805.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).nm -S). The largest:report4,302 B,track2,823 B (track_resolution_failure2,906 to 96 B), areserve_rehashof the path table 1,430 B,note731 B,source_of_module422 B.bundle.test.ts19.7 to 38.3 s (54 to 88 tests),css.test.ts12.0 to 12.9 s,html.test.ts5.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.report4,286 B,note731 B,Graph::source_of_module422 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.resolve_import_records(2,885),process_resolve_queue(485),is_done(79), and the success path ofon_parse_task_complete. Only address immediates differ.note,reportandsource_of_modulerun 0 times: a dev route of 72 modules with 2 saves and an idle request, abun buildof 401 modules, a dev bundle with a syntax error.BundleV2::init: 816 to 820 instructions forbun build, 823 to 827 for a dev server bundle (the newVec).BundleV2is 2,232 to 2,256 B. A dev server bundle runs 2 more (cmp,jne) when the scan is done.bun build: the error output of 8 fixtures and the output of a 401 module build are byte-identical to main.The watch store and the
node_modulesrule (the last two commits).beforeis 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_failure2,900 to 96 B with the newtrack2,823 B,process_file_list5,241 to 5,392 B,free_entry372 to 316 B,report4,270 to 4,302 B.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_serverand the watcher callback differ only in field offsets.DevServergrows 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 scratchsize_ofconstant that is not committed: the debug build has no type information forgdb ptype.process_file_listruns 758, 535 and 572 before, and 762, 539 and 576 now (+4 for each call).insert, 0 directory opens of the resolver, 0 evictions, before and now.catch syscall, debug build). The save that finds the barrel missing:openat3 to 1,getdents642 to 0. The same with the directory gone: failingopenat2 to 1. A change in the watched directory with one pending dependency:openat4 to 0,getdents644 to 0, failingaccess0 to 2. The removal of the watched directory: failingopenat4 to 0, failingaccess0 to 2.readdir, before and now.resolver.rs:1006), so the store already opened its own.Tests
missing_sources.rs,source_of_module, the loop ofon_file_deleted, the watch rule, the call ofnote): each fails at least one test.insert, and the absolute-path guards oftrack_missing_file.before. Two of them pass with only the lookup deleted and the resolve kept, and fail without thenode_modulesrule.test/bake/,test/bake/dev/andbun-serve-html*.test.ts: 204 pass, 2 skip. The release build: 125 of 125.test/bundler/,test/bundler/esbuild/and resolve errors, 1,119 pass. Two tests ofproduction.test.tsand three--compiletests ofcli.test.tsneed--timeouton a debug build here.test/internal/source-lints/: 190 of 194 pass, and 4 that this change does not touch pass with a longer--timeouton the debug build.cargo clippy -p bun_bundler -p bun_runtime: no new warning.bun run rust:check-allforx86_64-pc-windows-msvc,aarch64-apple-darwinandx86_64-unknown-freebsd.dev.deleteand skipwin32, 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.tsthere: 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_modulesrule, and it left rows 3 and 6 to the resolver (#40279) and to the store bookkeeping (#46916).