playwright: [Bug]: 1.48.0 missing chromium-bidi dependency
Version
1.48.0
Steps to reproduce
- Clone my repo at https://github.com/halljus/playwright-1.48.0-repro
- npm install
- npx playwright install
- npm run dev
- Browse to http://localhost:5173
Observe in the server console that the ~bundler~ compiler (esbuild) cannot resolve chromium-bidi.
Expected behavior
It should just work (either by not requiring a devDependencies library, promoting it to dependencies, or updating documentation with further instructions).
This error does not occur in playwright v1.47.2, the latest version prior to v1.48.0.
Actual behavior
✘ [ERROR] Could not resolve "chromium-bidi/lib/cjs/bidiMapper/BidiMapper"
node_modules/playwright-core/lib/server/bidi/bidiOverCdp.js:7:49:
7 │ var bidiMapper = _interopRequireWildcard(require("chromium-bidi/lib/cjs/bidiMapper/BidiMapper"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "chromium-bidi/lib/cjs/bidiMapper/BidiMapper" as external to exclude it from
the bundle, which will remove this error and leave the unresolved path in the bundle. You can also
surround this "require" call with a try/catch block to handle this failure at run-time instead of
bundle-time.
✘ [ERROR] Could not resolve "chromium-bidi/lib/cjs/cdp/CdpConnection"
node_modules/playwright-core/lib/server/bidi/bidiOverCdp.js:8:56:
8 │ var bidiCdpConnection = _interopRequireWildcard(require("chromium-bidi/lib/cjs/cdp/CdpConnection"));
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "chromium-bidi/lib/cjs/cdp/CdpConnection" as external to exclude it from the
bundle, which will remove this error and leave the unresolved path in the bundle. You can also
surround this "require" call with a try/catch block to handle this failure at run-time instead of
bundle-time.
11:01:44 AM [vite] error while updating dependencies:
Error: Build failed with 2 errors:
node_modules/playwright-core/lib/server/bidi/bidiOverCdp.js:7:49: ERROR: Could not resolve "chromium-bidi/lib/cjs/bidiMapper/BidiMapper"
node_modules/playwright-core/lib/server/bidi/bidiOverCdp.js:8:56: ERROR: Could not resolve "chromium-bidi/lib/cjs/cdp/CdpConnection"
at failureErrorWithLog (C:\Users\user\dev\playwright-1.48.0-repro\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15)
at C:\Users\user\dev\playwright-1.48.0-repro\node_modules\vite\node_modules\esbuild\lib\main.js:945:25
at C:\Users\user\dev\playwright-1.48.0-repro\node_modules\vite\node_modules\esbuild\lib\main.js:1353:9
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Additional context
The repro is a fresh Remix project, but it’s a Vite issue.
Relevant code:
- https://github.com/microsoft/playwright/blob/bc30cc795e7a9f148039de77dd790cf44097450e/packages/playwright-core/src/server/bidi/bidiChromium.ts#L40
- https://github.com/microsoft/playwright/blob/bc30cc795e7a9f148039de77dd790cf44097450e/packages/playwright-core/src/server/bidi/bidiOverCdp.ts#L17
Environment
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 13th Gen Intel(R) Core(TM) i5-1345U
Memory: 38.74 GB / 63.64 GB
Binaries:
Node: 20.17.0 - ~\AppData\Local\nvs\default\node.EXE
npm: 10.8.2 - ~\AppData\Local\nvs\default\npm.CMD
IDEs:
VSCode: 1.94.1 - C:\Users\user\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
Languages:
Bash: 5.1.16 - C:\WINDOWS\system32\bash.EXE
npmPackages:
playwright: 1.48.0 => 1.48.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 21 (4 by maintainers)
Commits related to this issue
- fix: 🐛 Exclude playwright from build Refs: https://github.com/microsoft/playwright/issues/33031 — committed to TheJiahao/TheJiahao.github.io by TheJiahao 2 years ago
- [ci] Fixes Playwright tests The issue was the following error: [ERROR] Could not resolve "chromium-bidi/lib/cjs/bidiMapper/BidiMapper" The fix has been found here: https://github.com/microsoft/playw... — committed to gephi/gephi-lite by jacomyal 2 years ago
Why is this closed ? bug still present in 1.49.0.
Closing as per above. Not sure if it is worth bringing up with the esbuild / vite folks to let them know that they could do a better job at detecting playwright as a server-side only import.
Could you guys reopen this issue. It has not been fixed.
@halljus Im seeing this issue when using vitest, which use vite, however I can’t configure its server to exclude chromium-bidi like you did
I’m using vitest “browser” feature with
playwrighthttps://vitest.dev/guide/browser/#examplesThis is my vitest.worspace.mjs
my
global-setup.mjsis just starting another application in the background, and has nothing to do with this error, so I’m not posting it here.dev dependencies
I also had to run
npx playwright installto download browsers, which was a recommended command playwright itself showed on the terminal.@AllanOricil Yeah, I don’t know. I still think Microsoft needs to revisit the change in 1.48.0 rather than claiming all the different build tools in the ecosystem are wrong, but what do I know? They’re smarter than I. 🙂
I tried something like that but apparently I used the wrong option. This did work, though:
Vite’s dependency pre-bundling optimization is what was asking esbuild to resolve chromium-bidi.
This is still a problem using SST v2 reverting to 1.47.2 fixes the issue.
I might’ve misspoken by calling it a bundler, as I don’t think it’s bundling in this context.
The use case is using Playwright on the server in a Remix app ~(could be Next.js or any other modern web framework)~. It’s been working fine like this for as long as I can remember, it just stopped with 1.48.0 yesterday. 😛
There’s a comment right above the offending import:
Dynamically imported or not, wouldn’t bidiOverCdp’s dependencies (
chromium-bidi) need to be installed in consuming projects? Unless maybe there’s a check elsewhere in the calling code to only load bidiChromium.ts if developing locally within the Playwright project, but if there is - it doesn’t appear to be working.Marking
chromium-bidias external in ESBuild might make it work.Bundle-related item: https://github.com/microsoft/playwright/issues/35479
Ran into this when using
bun buildin a docker based setup.For future searchers, since nobody gave an explicit bun fix yet, here is one way to get around it with bun:
bun build **your build settings** --external electron --external chromium-bidi",Edit: see https://github.com/microsoft/playwright/issues/35479#issuecomment-2777607491
Use the below at your own risk. We no longer bundle Playwright in our projects.
Stale info
For what it’s worth, our team has been bundling playwright for some time now. We use express + playwright to run a pdf-service (you give it an html string, it gives you a pdf).
Here are some files for reference if it helps.
excludeVendorFromSourceMapPluginpart if you don’t care about that)chromium-bidimarked as external as mentioned aboveesbuild.config.mjs:DockerfileResolved this in Nuxt 3 config with:
So i’m seeing this same issue when trying to build a Nuxt3 (3.13.2) app with
ssr: true. I set the optimizeDeps, as suggested in the comment above but it still errors.I mitigated this by downgrading and pinning the exact version 1.47.2 in my package.json
"@playwright/test": "1.47.2"However, what really confuses me is that this error comes up when i run the build
nuxt build. Why is playwright involved in that at all? this is bundling my frontend code as a universal app so why the test framework?The only place playwright is called inside my code base is the test files (excluded and added to .nuxtignore just in case). and in the npm test script. So… why is it attempting to bundle playwright?
bun buildalso has the same error with1.48but not1.47. I’m pre-compiling a typescript project to run in a container. I think this is normal?I don’t think playwright is ready to be bundled, what is your use case?