{"record":{"id":"74135d371869b370","repo":"mastra-ai/mastra","slug":"could-not-parse-plugin-manifest-file-error-i","errorCode":null,"errorMessage":"Could not parse ${PLUGIN_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Could not parse (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/plugins/manifest.ts","lineNumber":24,"sourceCode":"export type PluginManifestEntry = {\n  id: string;\n  name?: string;\n  entry: string;\n};\n\nexport type PluginManifest = {\n  plugins: PluginManifestEntry[];\n};\n\nexport function loadPluginManifest(rootDir: string): PluginManifest | undefined {\n  const manifestPath = path.join(rootDir, PLUGIN_MANIFEST_FILE);\n  if (!fs.existsSync(manifestPath)) return undefined;\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n  } catch (error) {\n    throw new Error(\n      `Could not parse ${PLUGIN_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)}`,\n    );\n  }\n\n  if (!parsed || typeof parsed !== 'object' || !Array.isArray((parsed as { plugins?: unknown }).plugins)) {\n    throw new Error(`${PLUGIN_MANIFEST_FILE} must contain a plugins array`);\n  }\n\n  return {\n    plugins: (parsed as { plugins: unknown[] }).plugins.map((entry, index) => validateManifestEntry(entry, index)),\n  };\n}\n\nexport function savePluginManifest(rootDir: string, manifest: PluginManifest): void {\n  fs.writeFileSync(path.join(rootDir, PLUGIN_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`);\n}\n\nexport function upsertPluginManifestEntry(rootDir: string, entry: PluginManifestEntry): void {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/plugins/manifest.ts#L6-L42","documentation":"loadPluginManifest() reads `.mastracode-plugin.json` from the given rootDir and JSON.parse fails. The library wraps the parse error with the manifest filename and rethrows so you know which file is malformed.","triggerScenarios":"Calling loadPluginManifest, getSingleManifestPlugin, or anything that boots the manifest plugin when `.mastracode-plugin.json` exists in rootDir but contains invalid JSON: truncated writes, comments in JSON, trailing commas, BOM, or hand-edits.","commonSituations":"Hand-editing the manifest and leaving a trailing comma; a failed save leaving a partially written file; copy-pasting JSON with comments or single quotes; non-UTF8 encoding.","solutions":["Open `.mastracode-plugin.json` in the reported rootDir and fix the JSON syntax error named in the message.","Validate the file with `JSON.parse(fs.readFileSync(...))` or `node -e` / a JSON linter before rerunning.","Regenerate the file via savePluginManifest/upsertPluginManifestEntry instead of editing by hand.","Check the file encoding — strip BOM and ensure UTF-8."],"exampleFix":"// before (invalid JSON)\n{ \"plugins\": [{ \"id\": \"a\", \"entry\": \"./a.ts\", }] }\n// after\n{ \"plugins\": [{ \"id\": \"a\", \"entry\": \"./a.ts\" }] }","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst raw = fs.readFileSync(manifestPath, 'utf8').replace(/^\\uFEFF/, '');\ntry { JSON.parse(raw); } catch (e) { throw new Error(`Invalid .mastracode-plugin.json: ${(e as Error).message}`); }","typeGuard":"function isValidJson(text: string): boolean {\n  try { JSON.parse(text); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  const manifest = loadPluginManifest(rootDir);\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Could not parse')) {\n    console.error('Fix .mastracode-plugin.json JSON syntax:', error.message);\n    process.exitCode = 1;\n    return;\n  }\n  throw error;\n}","preventionTips":["Never hand-edit JSON with trailing commas or comments — validate after edits.","Always write the manifest via savePluginManifest so it is well-formed.","Strip BOM and ensure UTF-8 encoding of the file.","Run a JSON linter in CI over `.mastracode-plugin.json` files."],"tags":["json","manifest","parse-error","config"],"backgroundTag":"invalid-json-config","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}