Skip to content

Commit 85349f9

Browse files
committed
Add diagnostic info for package.json parse errors
1 parent a2ca2cc commit 85349f9

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

scripts/install-npm-packages.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,18 @@ async function installPackage(packageInfo) {
632632

633633
// Remove the "files" field so pnpm includes all files (including tests).
634634
// Also remove unnecessary lifecycle scripts that could interfere with testing.
635-
const editablePkgJson = await readPackageJson(pkgJsonPath, {
636-
editable: true,
637-
})
635+
let editablePkgJson
636+
try {
637+
editablePkgJson = await readPackageJson(pkgJsonPath, {
638+
editable: true,
639+
})
640+
} catch (parseError) {
641+
// If JSON parsing fails, read the file content to help diagnose the issue.
642+
const fileContent = await fs.readFile(pkgJsonPath, 'utf8')
643+
throw new Error(
644+
`Invalid package.json: ${parseError.message}. File size: ${pkgJsonStats.size}, Content preview: ${fileContent.slice(0, 200)}`,
645+
)
646+
}
638647
const { scripts } = editablePkgJson.content
639648
const cleanedScripts = scripts ? { __proto__: null } : undefined
640649
if (scripts) {

0 commit comments

Comments
 (0)