quasarframework/quasar · error
extendPackageJson() - "${extPkg}" is malformed. Exiting...
Error message
extendPackageJson() - "${extPkg}" is malformed. Exiting... What it means
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.
Source
Thrown at app-vite/lib/app-extension/api-classes/InstallAPI.js:161
const source = path.resolve(dir, extPkg)
if (!fs.existsSync(source)) {
this.logger.warn(
`extendPackageJson() - cannot locate ${extPkg}. Skipping...`
)
return
}
if (fs.lstatSync(source).isDirectory()) {
this.logger.warn(
`extendPackageJson() - "${extPkg}" is a folder instead of file. Skipping...`
)
return
}
try {
extPkg = JSON.parse(fs.readFileSync(source, 'utf8'))
} catch {
this.logger.warn(
`extendPackageJson() - "${extPkg}" is malformed. Exiting...`
)
warn()
process.exit(1)
}
}
if (Object(extPkg) !== extPkg || Object.keys(extPkg).length === 0) return
const pkg = merge({}, this.ctx.pkg.appPkg, extPkg)
fs.writeFileSync(
this.resolve.app('package.json'),
stringifyJSON(pkg),
'utf8'
)
if (View on GitHub (pinned to 4841521b5f)
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
Example fix
// before (package-ext.json, invalid)
{ "scripts": { "test": "echo ok",, } }
// after
{ "scripts": { "test": "echo ok" } } Defensive patterns
Strategy: validation
Validate before calling
// validate the fragment before handing it to extendPackageJson
const fs = require('fs')
const raw = fs.readFileSync(source, 'utf8').replace(/^\uFEFF/, '') // strip BOM
try {
JSON.parse(raw)
} catch (e) {
throw new Error(`Invalid JSON in ${source}: ${e.message}`)
} Prevention
- 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
When it happens
Trigger: api.extendPackageJson('./file.json') where the file exists but contains invalid JSON (trailing commas, comments, BOM, truncation, or non-JSON content like JS).
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- extendPackageJson() - cannot locate ${extPkg}. Skipping...
- extendPackageJson() - "${extPkg}" is a folder instead of fil
- Failed to render template "${sourcePath}". This may break th
- Could not read BEX manifest. Please check its syntax.
- Quasar App Extension is not installed...
AI-assisted analysis of quasarframework/quasar@4841521b5f (2026-08-30).
Data as JSON: /api/errors/9a50e9ab715d8743.
Report an issue: GitHub.