Repository navigation
fix: Playwright detection failing in prebuilt release binaries - #332
Conversation
|
📚 No documentation changes were needed for this PR (Job ID: |
Kimchi Code Review
Summary📊 Review Score: 82/100 (overall code quality — 0 lowest, 100 highest) 🧪 Tests: no — No tests were added or modified to verify the patched Playwright behavior in Bun compiled binaries or to guard against regressions in stack-trace filtering. 📝 Found 2 issue(s). See inline comments for details. What to expectKimchi will analyze the changes in this pull request and post:
The review typically completes within a few minutes. This comment will be updated once the review is ready. Interact with Kimchi
ConfigurationReviews are configured by your organization admin. Powered by Kimchi — AI-powered code review by CAST AI |
There was a problem hiding this comment.
📊 Review Score: 82/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)
🧪 Tests: no — No tests were added or modified to verify the patched Playwright behavior in Bun compiled binaries or to guard against regressions in stack-trace filtering.
📝 Found 2 issue(s). See inline comments for details.
Address review feedback: - Narrow bare catch to only handle MODULE_NOT_FOUND, re-throw unexpected errors (corrupt installs, permission errors) - Replace TODO placeholder with actual upstream link: oven-sh/bun#29066
Fix Playwright detection failing in prebuilt release binaries
Problem
When installing kimchi from prebuilt release artifacts (
curl -fsSL .../install.sh | bash), Playwright is never detected — users always see the fallback warning:Installing locally via
pnpm run build:binary && pnpm run install:localworks fine.Root Cause
When Bun compiles the binary with
bun build --compile, it converts relativerequire.resolve()calls inside bundled dependencies into absolute paths from the build machine.In
playwright-core/lib/server/utils/nodePlatform.js, the line:gets compiled to:
This
require.resolve()runs at module initialization time (top-levelconst). On any machine other than the build machine, this path doesn't exist, sorequire.resolvethrows, the entire playwright-core module fails to initialize, and the error propagates up throughloadPlaywright()→playwrightAvailable = false→ fallback warning.Local build works because the hardcoded path points to the developer's own
node_moduleswhich still exist on the same machine. Release build fails because the path points to the CI runner's filesystem (/Users/runner/work/kimchi/kimchi/...).Fix
Added a pnpm patch for
playwright-core@1.59.1that wraps thecoreDirinitialization in a try-catch.coreDiris only used for stack-trace filtering (hiding playwright internals from error traces), so an empty string fallback is functionally safe.Patch removal criteria
This patch can be removed when either:
require.resolvein compiled binaries — Bun PR #29066 fixed__dirname/__filenamebutrequire.resolve()with relative paths still gets hardcoded.Kimchi Summary
What changed
Patches
playwright-coreto prevent runtimeMODULE_NOT_FOUNDerrors in Bun compiled binaries by falling back to__dirname-based path resolution whenrequire.resolve()fails.Why
Bun compiles relative
require.resolve()calls into absolute build-machine paths that are invalid at runtime. This causesplaywright-coreto crash when locating its package root inside a compiled binary.Key changes
patches/playwright-core@1.59.1.patch: Wrapsrequire.resolve("../../../package.json")inlib/server/utils/nodePlatform.jswith a try-catch block and falls back topath.resolve(__dirname, "../../..")onMODULE_NOT_FOUND.package.json: Registeredplaywright-core@1.59.1underpatchedDependencies.pnpm-lock.yaml: Updatedplaywright-coresnapshots to apply the new patch hash.Impact
playwright-coreto function correctly when bundled in Bun compiled binaries.