playwright: [BUG] Error: ENOENT: no such file or directory, open '/var/task/node_modules/playwright-core/browsers.json' on Vercel with Next.js
After upgrade Playwright to 1.9.2 this error is happening on Vercel functions.
2021-03-16T19:57:07.806Z undefined ERROR Error: ENOENT: no such file or directory, open '/var/task/node_modules/playwright-core/browsers.json'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at new Registry (/var/task/node_modules/playwright-core/lib/utils/registry.js:213:54)
at new Playwright (/var/task/node_modules/playwright-core/lib/server/playwright.js:46:23)
at Object.createPlaywright (/var/task/node_modules/playwright-core/lib/server/playwright.js:59:12)
at setupInProcess (/var/task/node_modules/playwright-core/lib/inprocess.js:24:37)
at Object.<anonymous> (/var/task/node_modules/playwright-core/lib/inprocess.js:42:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/var/task/node_modules/playwright-core/browsers.json'
}
RequestId: fafc5e6c-b338-4ba2-90b0-a019fd78923b Error: Runtime exited with error: exit status 1
Runtime.ExitError
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (7 by maintainers)
Commits related to this issue
- chore: read browser.json with require This fixes the compatibility on Vercel with Next.js when it's used in a serverless function. Next.js uses https://github.com/vercel/nft to trace down the dependen... — committed to mxschmitt/playwright by mxschmitt 3 years ago
- chore: read browsers.json with require This fixes the compatibility on Vercel with Next.js when it's used in a serverless function. Next.js uses https://github.com/vercel/nft to trace down the depende... — committed to mxschmitt/playwright by mxschmitt 3 years ago
- chore: read browsers.json with require (#6186) This fixes the compatibility on Vercel with Next.js when it's used in a serverless function. Next.js uses https://github.com/vercel/nft to trace down ... — committed to microsoft/playwright by mxschmitt 3 years ago
- Add playwright-core@next https://github.com/microsoft/playwright/issues/5862#issuecomment-823915087 — committed to jclem/mar.ink by jclem 3 years ago
- Use playwright-aws-lambda So, just using normal playwright was crashing with this error: https://github.com/microsoft/playwright/issues/5862 I didn't understand why everyone was using playwright-cor... — committed to openneo/impress-2020 by matchu 3 years ago
The issue should be fixed in the
npm install playwright-core@nextversion and lands in version 1.11. I tested it and it’s working for one of my projects.cc @BrunoQuaresma @jeadev @j2is @tiivik @dbredvick @zephraph
Hey folks, I don’t think this is a playwright issue. I also don’t think it’s cache issue. When Vercel prepares serverless functions, it traces what dependencies/files are used and only includes those in the payload. What’s likely happening here is that the tracing mechanism doesn’t “see” this browser.json file as a dependency and thus doesn’t upload it to the lambda. I wrote a little about the tracing process if you’re interested.
I fixed this in my PR above, but note that I’m not using a Next.js api function but rather a Vercel api function. That’s necessary because you’ll have to explicitly include the
browsers.jsonfile in vercel’s config in order to get it to work (and you can’t do that w/ next functions). Also, as mentioned in my linked blog post, Next server dependencies are all bundled together so by placing playwright (and therefore chromium) in your Next.js function you’re risking pushing yourself over the 50MB function limit.This issue should probably be reported to Vercel.
This could be fixed in playwright by removing the dynamic loading of browser.json if there’s appetite for that.
I feel like such a noob for posting this but I was able to fix this issue for myself. I guess they changed something internal on how they handle paths. I was importing a file like this -
const script = fs.readFileSync("./image.js", "utf-8");Used the dirname path and got rid of.const script = fs.readFileSync(__dirname + "/image.js", "utf-8");Now my serverless function is working again.I think @mxschmitt is right—this stopped working after @vercel/nft 0.12.0 was released.
0.12.0 was released 8 days ago, and I would guess it got deployed to Vercel’s infrastructure in the past few days, causing this issue to appear again for new deployments. @vercel/nft 0.11.2 does not have this issue.
I have created a test case and opened vercel/nft#211.
It seems this has broken again in the last 24 hours. I have a Vercel project I deployed yesterday that this is working for. Today, if I redeploy the same code (using the
--forceflag), I am getting thebrowsers.jsonerror.Still doing a bit more research to make sure…
I did some more investigation into this issue. It seems nft as @zephraph wrote is used to trace the files which are needed during the runtime does not detect that the
browsers.jsonis needed.See that line:
https://github.com/microsoft/playwright/blob/e81a3c5901e024f7c41edf023daad60c68ed093d/src/utils/registry.ts#L238
If it get replaced from
fs.readFileSynctorequire, it works. I created the following demonstration PR on their side, so hopefully they fix it, otherwise in Playwright it can be changed fromreadFileSyncwithJSON.parsetorequirewhich workarounds it.See here: https://github.com/vercel/nft/pull/184
And I’ve created a patch on Playwright side: https://github.com/microsoft/playwright/pull/6186
@mxschmitt I have no idea… I’m building an app and I’ve discovered this package yesterday. I’m quite confused on how to solve this issue I can’t find anything online. I tried to install the package at build-time in vercel but it doesn’t work either…