From 7ec57c0c18966c7148c4545ac66651b05c2bfbba Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 19 Apr 2021 22:06:04 +0200 Subject: [PATCH] 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 the dependencies which a serverless function is using which is currently not capable of detecting the browsers.json in our current setup. Previously we used require to load the browers.json which was replaced by readFileSync in #5318. Since then it was broken. Fixes #5862 --- src/utils/registry.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/registry.ts b/src/utils/registry.ts index 653f966958..4a440178e3 100644 --- a/src/utils/registry.ts +++ b/src/utils/registry.ts @@ -16,7 +16,6 @@ */ import { execSync } from 'child_process'; -import fs from 'fs'; import * as os from 'os'; import path from 'path'; import * as util from 'util'; @@ -235,7 +234,9 @@ export class Registry { } constructor(packagePath: string) { - const browsersJSON = JSON.parse(fs.readFileSync(path.join(packagePath, 'browsers.json'), 'utf8')); + // require() needs to be used there otherwise it breaks on Vercel serverless + // functions. See https://github.com/microsoft/playwright/pull/6186 + const browsersJSON = require(path.join(packagePath, 'browsers.json')); this._descriptors = browsersJSON['browsers'].map((obj: any) => { const name = obj.name; const revisionOverride = (obj.revisionOverrides || {})[hostPlatform];