{"record":{"id":"9a50e9ab715d8743","repo":"quasarframework/quasar","slug":"extendpackagejson-extpkg-is-malformed-ex","errorCode":null,"errorMessage":"extendPackageJson() - \"${extPkg}\" is malformed. Exiting...","messagePattern":"extendPackageJson\\(\\) - \"(.+?)\" is malformed\\. Exiting\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app-vite/lib/app-extension/api-classes/InstallAPI.js","lineNumber":161,"sourceCode":"      const source = path.resolve(dir, extPkg)\n\n      if (!fs.existsSync(source)) {\n        this.logger.warn(\n          `extendPackageJson() - cannot locate ${extPkg}. Skipping...`\n        )\n        return\n      }\n      if (fs.lstatSync(source).isDirectory()) {\n        this.logger.warn(\n          `extendPackageJson() - \"${extPkg}\" is a folder instead of file. Skipping...`\n        )\n        return\n      }\n\n      try {\n        extPkg = JSON.parse(fs.readFileSync(source, 'utf8'))\n      } catch {\n        this.logger.warn(\n          `extendPackageJson() - \"${extPkg}\" is malformed. Exiting...`\n        )\n        warn()\n        process.exit(1)\n      }\n    }\n\n    if (Object(extPkg) !== extPkg || Object.keys(extPkg).length === 0) return\n\n    const pkg = merge({}, this.ctx.pkg.appPkg, extPkg)\n\n    fs.writeFileSync(\n      this.resolve.app('package.json'),\n      stringifyJSON(pkg),\n      'utf8'\n    )\n\n    if (","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/app-vite/lib/app-extension/api-classes/InstallAPI.js#L143-L179","documentation":"When the JSON fragment file passed to extendPackageJson() cannot be parsed (JSON.parse throws), this warning is logged, an extra warn() banner is shown, and the process exits with code 1 — the extension install aborts rather than continuing with a partially broken package merge.","triggerScenarios":"api.extendPackageJson('./file.json') where the file exists but contains invalid JSON (trailing commas, comments, BOM, truncation, or non-JSON content like JS).","commonSituations":"Hand-edited fragment with syntax mistakes; file saved with comments (JSONC) that strict JSON.parse rejects; encoding issues (UTF-16/BOM); wrong file passed that is actually JS config.","solutions":["Validate the JSON file (node -e \"JSON.parse(require('fs').readFileSync('file.json','utf8'))\" or an editor linter) and fix the syntax","Remove comments and trailing commas — strict JSON only","Re-save the file as UTF-8 without BOM","Or pass a function to extendPackageJson instead of a JSON file to sidestep parsing"],"exampleFix":"// before (package-ext.json, invalid)\n{ \"scripts\": { \"test\": \"echo ok\",, } }\n// after\n{ \"scripts\": { \"test\": \"echo ok\" } }","handlingStrategy":"validation","validationCode":"// validate the fragment before handing it to extendPackageJson\nconst fs = require('fs')\nconst raw = fs.readFileSync(source, 'utf8').replace(/^\\uFEFF/, '') // strip BOM\ntry {\n  JSON.parse(raw)\n} catch (e) {\n  throw new Error(`Invalid JSON in ${source}: ${e.message}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint JSON fragments in CI (e.g. `node --check`-style JSON.parse validation)","No comments or trailing commas — strict JSON only","Save fragments as UTF-8 without BOM","Use the function form extendPackageJson(pkg => {...}) to skip file parsing entirely"],"tags":["app-extension","install","package-json","json-parse"],"backgroundTag":"malformed-json","analyzedSha":"4841521b5f635a971eb9e2710e5542efd194691b","analyzedAt":"2026-08-30T01:13:14.944Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}