Skip to content

Commit 921bb36

Browse files
fix: handle malformed JSON in workspace package.json files gracefully
readPackageJson now catches SyntaxError from malformed JSON and returns an empty object instead of crashing. This prevents workspace discovery from aborting when a subdirectory has an invalid package.json. Previously, a broken package.json in any workspace subdirectory would crash the entire scan with an unhandled SyntaxError. Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
1 parent e13043c commit 921bb36

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/react-doctor/src/utils/read-package-json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const readPackageJson = (packageJsonPath: string): PackageJson => {
55
try {
66
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
77
} catch (error) {
8+
if (error instanceof SyntaxError) {
9+
return {};
10+
}
811
if (error instanceof Error && "code" in error) {
912
const { code } = error as { code: string };
1013
if (code === "EISDIR" || code === "EACCES") {

0 commit comments

Comments
 (0)