Vite front end keeps serving a failed build after the missing/broken imported module is fixed
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 77/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript, vite
- Lĩnh vực
- build-system, developer-experience
Hướng nghiên cứu
Bắt đầu tại vite.mjs, ở build() và bước kiểm tra bộ nhớ đệm fresh(prior), sau đó dùng tập lệnh repro.mjs được cung cấp để tái hiện việc bản dựng thất bại vẫn nằm trong bộ nhớ đệm sau khi lib/part.rx được khôi phục. Issue đề xuất chỉ tái sử dụng các bản dựng có out.modules; hãy xác minh rằng các trường hợp thiếu mô-đun, NOT_EXPORTED và tệp không đọc được sẽ được khắc phục ở lần biên dịch tiếp theo, còn các bản dựng thành công không thay đổi vẫn nằm trong bộ nhớ đệm.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Found while building a component library on ReactiveScript. Found and diagnosed with Claude Fable 5.2, and reproduced, tested and written up with Claude Opus 5.5 (both in Claude Code), which also ran the reproductions; the reproduction was rerun from a clean npm install before posting.
Summary
@reactivescript/compiler 0.3.1, vite.mjs: after a program fails to compile because of a module it imports, the failed build stays cached after that module is restored or fixed. The error goes away only when the entry or the file named in the diagnostic gets a new mtime, or when the dev server restarts.
Reproduction
In an empty folder with {"type": "module"} in package.json, run pnpm add @reactivescript/[email protected]. Only the compiler is needed; this script doesn't use the peer dependency @solidjs/vite-plugin. Then add these files:
entry.rx
import { Wrapper } from "./ui/wrapper.rx"
export default component App() {
<Wrapper label="hello" />
}
ui/wrapper.rx
import { Part } from "../lib/part.rx"
export component Wrapper(props: { label: string }) {
<div class="wrapper"><Part label={props.label} /></div>
}
lib/part.rx
export component Part(props: { label: string }) {
<span class="part">{props.label}</span>
}
repro.mjs
import rx from "@reactivescript/compiler/vite";
import { readFileSync, renameSync } from "node:fs";
import path from "node:path";
const entry = path.resolve("entry.rx");
const front = rx();
const compile = label => {
try {
front.compile(readFileSync(entry, "utf8"), { id: entry, moduleId: entry, solid: { generate: "dom" }, addWatchFile() {} });
console.log(`${label}: ok`);
} catch (e) {
console.log(`${label}: ${e.message.split("\n")[0]}`);
}
};
compile("1. all files present");
renameSync("lib/part.rx", "part.rx.away");
compile("2. lib/part.rx missing");
renameSync("part.rx.away", "lib/part.rx"); // a rename keeps the file's mtime: it comes back unchanged
compile("3. lib/part.rx back");
node repro.mjs prints the following (the project directory is shown as <dir>):
1. all files present: ok
2. lib/part.rx missing: <dir>/ui/wrapper.rx:1: error MODULE_NOT_FOUND [MO-6] no module ../lib/part.rx (from <dir>/ui/wrapper.rx)
3. lib/part.rx back: <dir>/ui/wrapper.rx:1: error MODULE_NOT_FOUND [MO-6] no module ../lib/part.rx (from <dir>/ui/wrapper.rx)
Expected: step 3 prints ok. Calling the native app() directly at that point succeeds.
Other cases that behave the same way:
- The first compile happens while
lib/part.rxis missing. NOT_EXPORTED: renamePartinlib/part.rx, compile, rename it back. The error stays.lib/part.rxis unreadable (chmod 000, reported as MO-6) and then made readable again.
In a dev server this showed up when a directory of imported .rx files was deleted and copied back. Every program that imported it kept returning 500 until its entry or importer was touched.
Cause
build() reuses a cached build while fresh(prior) holds, and fresh compares the mtimes in stamps. For a failed build, stamps covers only the entry and the files named by out.diagnostics.map(d => d.file):
const files = out.modules ? Object.keys(out.modules) : out.diagnostics ? [...new Set([entry, ...out.diagnostics.map(d => d.file)])] : [entry];
A diagnostic's file is where the error is reported, which is not always where it comes from. MO-6 names the importer, not the missing module, and NOT_EXPORTED names the importer, not the exporting file. So when the real cause is fixed, nothing in stamps changes and the failed build is served again.
There is a knock-on effect. The failed build replaces the good build under the same key, so containing() finds no program for the entry's ?rx-dep modules and throws ... is imported as an .rx dependency, but no program built so far contains it until the entry compiles successfully again.
Suggested fix
Reuse only successful builds:
--- a/vite.mjs
+++ b/vite.mjs
@@ -42,7 +42,8 @@
function build(entry, target, moduleName, spa) {
const key = `${entry}\0${target}\0${moduleName}\0${spa}`;
const prior = builds.get(key);
- if (prior && fresh(prior)) return prior;
+ // a failed build's stamps cannot cover what it failed to find, so only a successful build is reused
+ if (prior?.out.modules && fresh(prior)) return prior;
const out = JSON.parse(app(entry, target, moduleName, spa));
if (out.modules) out.modules = Object.fromEntries(Object.entries(out.modules).map(([p, m]) => [path.resolve(p), m]));
const files = out.modules ? Object.keys(out.modules) : out.diagnostics ? [...new Set([entry, ...out.diagnostics.map(d => d.file)])] : [entry];
With this patch, all of the cases above recover on the next compile, and a successful build is still reused when nothing has changed. I tested this with the script above, not in a full Vite dev server.
The trade-off: while a program is failing, every compile call rebuilds it natively. This seems acceptable because failures are transient and a build is cheap. On a 13-module program a successful build took about 6 ms.
I also tried stamping the missing module's path, parsed out of the MO-6 message, but rejected it. It fixes the missing-file case but not NOT_EXPORTED or the unreadable-file case. The diagnostic also has no field holding the missing path, so the fix would depend on the message wording.
One related limit that this patch does not address: if a ?rx-dep module is requested before its entry recompiles, it still throws until the entry is requested.
Environment
@reactivescript/compiler0.3.1@solidjs/vite-plugin3.0.1- Vite 8.3.8
- Node 26.13.1, macOS 27.2.1
- Ngôn ngữ chính
- TypeScript
- Star
- 127
- Fork
- 7
- Merge trung bình
- 15 giờ 42 phút
- Pull request đã merge (30 ngày)
- 63
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/reactivescript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
solidjs/reactivescript#96 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
solidjs/reactivescript#77 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
solidjs/reactivescript#74 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
solidjs/reactivescript#97 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
solidjs/reactivescript#83 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/reactivescript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
GetStream/stream-chat-react#3467 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vercel-labs/ui#1139 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
generate_image reference URL guard lets through IPv4-mapped IPv6 hosts and 100.64.0.0/10Có thể đã có người làm @goranai đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] IntegerRange.contains counts a non-integer just above max as inside an inclusive rangeĐang mởbot:ai-assisted component:platform-js status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
midnightntwrk/platform-js#93 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100