From 6f6e5de0ad8418328d52f58f4786f78b70cc6d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 18 Sep 2023 18:09:35 +0900 Subject: [PATCH] fix: handle errors during `hasWorkspacePackageJSON` function (#14394) --- packages/vite/src/node/server/searchRoot.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/searchRoot.ts b/packages/vite/src/node/server/searchRoot.ts index fb8c9c4cfc215a..edb7a76946266e 100644 --- a/packages/vite/src/node/server/searchRoot.ts +++ b/packages/vite/src/node/server/searchRoot.ts @@ -27,8 +27,12 @@ function hasWorkspacePackageJSON(root: string): boolean { if (!isFileReadable(path)) { return false } - const content = JSON.parse(fs.readFileSync(path, 'utf-8')) || {} - return !!content.workspaces + try { + const content = JSON.parse(fs.readFileSync(path, 'utf-8')) || {} + return !!content.workspaces + } catch { + return false + } } function hasRootFile(root: string): boolean {