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

  1. Validate the JSON file (node -e "JSON.parse(require('fs').readFileSync('file.json','utf8'))" or an editor linter) and fix the syntax
  2. Remove comments and trailing commas — strict JSON only
  3. Re-save the file as UTF-8 without BOM
  4. 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

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

Related errors


AI-assisted analysis of quasarframework/quasar@4841521b5f (2026-08-30). Data as JSON: /api/errors/9a50e9ab715d8743. Report an issue: GitHub.