Skip to content

Commit d12c3a6

Browse files
cliffhallclaude
andcommitted
ci: fix playwright resolution in the browser smoke (CI failure)
The bare `import("playwright")` resolved relative to the script's own directory (scripts/), not the cwd — so `cd clients/web` in the npm script never made it resolvable. It only passed locally because an ancestor node_modules happened to carry playwright; CI has none, so it failed with "Cannot find package 'playwright'". Resolve it explicitly from clients/web via createRequire, independent of cwd and ancestor dirs. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent bb80837 commit d12c3a6

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎scripts/smoke-web-browser.mjs‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,31 @@
2727
* errors are collected and printed as diagnostics, and only fail the run when
2828
* they carry the externalized-module signature.
2929
*
30-
* Run from the clients/web directory (`npm run smoke:web:browser` does
31-
* `cd clients/web` first) so `import("playwright")` resolves against that
32-
* client's node_modules. Repo-root paths are derived inside the shared helper
33-
* from import.meta.url, so the cwd change doesn't affect which build tree runs.
30+
* Playwright lives in clients/web's node_modules, so it's resolved with a
31+
* `createRequire` based at clients/web/package.json rather than a bare
32+
* `import("playwright")`. A bare ESM specifier resolves relative to *this
33+
* script's* directory (scripts/), not the cwd — so `cd clients/web` in the npm
34+
* script would NOT make it resolvable, and it only appeared to work locally
35+
* when an ancestor node_modules happened to carry playwright (it fails in CI,
36+
* which has none). createRequire pins resolution to clients/web regardless of
37+
* cwd or ancestor dirs.
3438
*
3539
* Expects `clients/web/dist` and `clients/launcher/build` to be built first —
3640
* the validate / CI ordering guarantees this.
3741
*/
3842

43+
import { createRequire } from "node:module";
3944
import { setTimeout as delay } from "node:timers/promises";
45+
import { fileURLToPath } from "node:url";
46+
import { dirname, resolve } from "node:path";
4047
import { startProdWebServer } from "./lib/prod-web-server.mjs";
4148

49+
const scriptDir = dirname(fileURLToPath(import.meta.url));
50+
// Resolve playwright from clients/web (where it's installed) no matter the cwd.
51+
const requireFromWeb = createRequire(
52+
resolve(scriptDir, "..", "clients/web/package.json"),
53+
);
54+
4255
const HOST = "127.0.0.1";
4356
// Distinct from smoke:web's SMOKE_WEB_PORT so overriding one doesn't make both
4457
// back-to-back smokes bind the same port (→ EADDRINUSE on the second).
@@ -78,16 +91,16 @@ async function fail(message) {
7891
}
7992

8093
async function loadChromium() {
81-
let playwright;
94+
let chromium;
8295
try {
83-
playwright = await import("playwright");
96+
({ chromium } = requireFromWeb("playwright"));
8497
} catch (err) {
8598
throw new Error(
86-
`could not load Playwright — run \`npx playwright install --with-deps chromium\` (${err instanceof Error ? err.message : String(err)})`,
99+
`could not load Playwright from clients/web — run \`npx playwright install --with-deps chromium\` (${err instanceof Error ? err.message : String(err)})`,
87100
);
88101
}
89102
try {
90-
return await playwright.chromium.launch({ headless: true });
103+
return await chromium.launch({ headless: true });
91104
} catch (err) {
92105
throw new Error(
93106
`chromium failed to launch — on a bare Linux box run \`npx playwright install --with-deps chromium\` for the system libraries (${err instanceof Error ? err.message : String(err)})`,

0 commit comments

Comments
 (0)