{"record":{"id":"f4d3aec5fc7f0be5","repo":"vuejs/vue-cli","slug":"the-package-json-is-malformed","errorCode":null,"errorMessage":"The package.json is malformed","messagePattern":"The package\\.json is malformed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@vue/cli/lib/util/getPkg.js","lineNumber":20,"sourceCode":"// See issue #1815\n\nconst fs = require('fs')\nconst path = require('path')\n\nfunction getPackageJson (projectPath) {\n  const packagePath = path.join(projectPath, 'package.json')\n\n  let packageJson\n  try {\n    packageJson = fs.readFileSync(packagePath, 'utf-8')\n  } catch (err) {\n    throw new Error(`The package.json file at '${packagePath}' does not exist`)\n  }\n\n  try {\n    packageJson = JSON.parse(packageJson)\n  } catch (err) {\n    throw new Error('The package.json is malformed')\n  }\n\n  return packageJson\n}\n\nmodule.exports = function getPkg (context) {\n  const pkg = getPackageJson(context)\n  if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {\n    return getPackageJson(path.resolve(context, pkg.vuePlugins.resolveFrom))\n  }\n  return pkg\n}\n","sourceCodeStart":2,"sourceCodeEnd":33,"githubUrl":"https://github.com/vuejs/vue-cli/blob/7eb93c169c7520935252e2473387f923ef80d856/packages/@vue/cli/lib/util/getPkg.js#L2-L33","documentation":"Thrown by getPackageJson in getPkg.js when the package.json file exists and is readable but fails JSON.parse — meaning the file content is not valid JSON. The catch wraps any parse error (unexpected token, trailing comma, etc.) into this generic message.","triggerScenarios":"Running a Vue CLI command in a project whose package.json contains invalid JSON: unquoted keys, trailing commas, single-quoted strings, comments, or corrupted/truncated content.","commonSituations":"Manual editing of package.json introduced a syntax error (e.g., trailing comma, missing quote). A merge conflict left conflict markers in the file. A tool or editor accidentally corrupted the file. Copy-pasting from documentation that used JS object shorthand.","solutions":["Validate the JSON: `node -e \"JSON.parse(require('fs').readFileSync('package.json','utf8'))\"` or use an online JSON validator.","Common fixes: remove trailing commas, ensure all keys and string values use double quotes, remove comments.","Check for merge conflict markers (<<<<, ====, >>>>) and resolve them.","Run `npm install` — npm itself will often report the exact parse error location."],"exampleFix":"// before (package.json)\n{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\",   <-- trailing comma\n}\n// after\n{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"const fs = require('fs');\ntry {\n  JSON.parse(fs.readFileSync('package.json', 'utf-8'));\n} catch (e) {\n  console.error('package.json is invalid JSON:', e.message);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const pkg = getPkg(context);\n} catch (e) {\n  if (e.message === 'The package.json is malformed') {\n    console.error('Fix package.json JSON syntax. Run: node -e \"JSON.parse(require(\\'fs\\').readFileSync(\\'package.json\\',\\'utf8\\'))\"');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Validate package.json after manual edits with `npm install` or a JSON linter.","Resolve all git merge conflict markers in package.json.","Use double quotes for all keys and string values, avoid trailing commas and comments.","Consider using an editor with JSON validation/autocomplete."],"tags":["package-json","json","validation","filesystem","corruption"],"backgroundTag":null,"analyzedSha":"7eb93c169c7520935252e2473387f923ef80d856","analyzedAt":"2026-08-13T10:13:37.803Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}