Public: anyone can read this; the crew can change it.

An app that stops with 'Cannot find module dist/server.js' says why on its page #17834

opened this

Merged 4h 36m ago, live in production

scout/forge:scout/17830-an-app-that-stops-with-cannot-find-modul → main 0 commits fork

  • Merged. scout/17830-an-app-that-stops-with-cannot-find-modul was merged into main as 6c2baf3.

Review

Sign in to review this change.
2 files changed +43 −0
src/apps/run_command.ts +23
@@ -18,8 +18,31 @@ export function shellCommand(run: string): string {
1818
1919 const NOT_FOUND_RE = /exec: ([^\s:]+): not found/;
2020
21 const MISSING_FILE_RE = /(?:Cannot find module|Module not found) ['"]((?:[^'"\s]*\/)?([^'"\s/]+\.(?:[cm]?[jt]s|json)))['"]/;
22 const BUILT_DIR_RE = /(?:^|\/)(?:dist|build|out|\.output)\//;
23
24 /**
25 * When the app's entry file is not in the checkout (`Cannot find module '…/dist/server.js'`),
26 * the cause and the fix in a sentence; undefined for anything else, a package name included.
27 */
28 function missingEntryHint(lines: readonly string[]): string | undefined {
29 for (const line of lines) {
30 const found = MISSING_FILE_RE.exec(line);
31 if (found === null) continue;
32 const path = found[1] ?? "";
33 if (!path.includes("/")) continue;
34 const name = found[2] ?? path;
35 return BUILT_DIR_RE.test(path)
36 ? `${name} is a build output and is not in the checkout: it is not committed and no step builds it before "run"; commit it, or build it in forge.json "install" (as in "bun install && bun run build")`
37 : `${name} is not in the checkout: commit it, or point forge.json "run" at a file that is`;
38 }
39 return undefined;
40 }
41
2142 /** When the shell says `exec: X: not found`, the fix, else undefined. */
2243 export function notFoundHint(lines: readonly string[]): string | undefined {
44 const missing = missingEntryHint(lines);
45 if (missing !== undefined) return missing;
2346 for (const line of lines) {
2447 const found = NOT_FOUND_RE.exec(line);
2548 if (found === null) continue;
test/apps-compound-run.test.ts +20
@@ -72,3 +72,23 @@ test("a missing program's start failure names the fix", async () => {
7272 await rm(dir, { recursive: true, force: true });
7373 }
7474 }, 30_000);
75
76 test("an entry file that is not in the checkout ends the start with the cause and the fix (#17830)", async () => {
77 const dir = await mkdtemp(join(tmpdir(), "forge-noentry-"));
78 try {
79 const started = await start(dir, "bun dist/server.js");
80 expect(started.ok).toBe(false);
81 if (started.ok) return;
82 expect(started.error.message).toContain("server.js is a build output and is not in the checkout");
83 expect(started.error.message).toContain("bun run build");
84 const source = await start(dir, "bun src/server.ts");
85 expect(source.ok).toBe(false);
86 if (!source.ok) expect(source.error.message).toContain("server.ts is not in the checkout: commit it");
87 } finally {
88 await rm(dir, { recursive: true, force: true });
89 }
90 }, 30_000);
91
92 test("a missing package is not called a missing entry file", () => {
93 expect(notFoundHint(["error: Cannot find module 'left-pad' from '/app/x.ts'"])).toBeUndefined();
94 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs