prisma/prisma · error · Error
${path}: not valid JSON (${error instanceof Error ? error.me
Error message
${path}: not valid JSON (${error instanceof Error ? error.message : String(error)}) What it means
Thrown by the core 0.9→0.10 upgrade codemod (stamp-storage-types-kind) when `JSON.parse(raw)` fails on a `start-contract.json` or `end-contract.json` it discovered under a `migrations/` tree. Before stamping the `kind` discriminator the codemod must parse the snapshot; a structurally invalid file aborts the run. The parenthesised message is Node's native JSON parse error locating the bad token.
Source
Thrown at skills/upgrade/prisma-next-upgrade/upgrades/0.9-to-0.10/stamp-storage-types-kind.ts:319
if (typeof value === 'object') {
const entries = Object.entries(value as Record<string, unknown>);
if (entries.length === 0) return '{}';
const lines = entries.map(
([k, v]) => `${childIndent}${JSON.stringify(k)}: ${formatJson(v, indentLevel + 1)}`,
);
return `{\n${lines.join(',\n')}\n${indent}}`;
}
throw new Error(`Unsupported value: ${typeof value}`);
}
async function processFile(path: string): Promise<Result> {
const raw = await readFile(path, 'utf-8');
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch (error) {
throw new Error(
`${path}: not valid JSON (${error instanceof Error ? error.message : String(error)})`,
);
}
const outcome = processContract(parsed, path);
if (outcome.transformed === null) {
return { path, status: 'already-clean', stamped: 0 };
}
const serialised = `${formatJson(outcome.transformed)}\n`;
if (!dryRun) await writeFile(path, serialised, 'utf-8');
return { path, status: dryRun ? 'needs-fix' : 'fixed', stamped: outcome.stamped };
}
const contracts = await findContractSnapshots(projectRoot);
if (contracts.length === 0) {
console.error(`No start-contract.json / end-contract.json files found under ${projectRoot}.`);
process.exit(1);
}
View on GitHub (pinned to 1243cdffbe)
Solutions
- Open the file at the reported path and fix the syntax error at the position given in the parenthesised parse message.
- If corrupted by a merge conflict, resolve the markers and re-run (the codemod is idempotent).
- If the snapshot is disposable, regenerate it via the migration authoring tooling or restore from git, then re-run.
- Run with `--check` first to enumerate all affected files before applying edits.
Example fix
// before — migrations/0001/start-contract.json
{
"storage": {
"types": {
"Embedding1536": { "codecId": "pg/vector@1", ... },
} // <- trailing comma breaks JSON.parse
}
// after
{
"storage": {
"types": {
"Embedding1536": { "codecId": "pg/vector@1", ... }
}
}
} Defensive patterns
Strategy: try-catch
Validate before calling
import { readFile } from 'node:fs/promises';
// Pre-validate every start-/end-contract.json before running the stamp upgrade.
async function assertContractSnapshotsAreValidJson(paths: string[]): Promise<void> {
for (const path of paths) {
const raw = await readFile(path, 'utf-8');
try { JSON.parse(raw); }
catch (error) {
const msg = error instanceof Error ? error.message : String(error);
throw new Error(`Refusing to run upgrade: ${path} is not valid JSON (${msg})`);
}
}
} Try / catch
try {
await runStampUpgrade(projectRoot);
} catch (error) {
if (error instanceof Error && error.message.includes(': not valid JSON (')) {
const offending = error.message.split(':')[0];
console.error(`Stamp upgrade aborted: regenerate ${offending} via the CLI, then re-run.`);
process.exit(1);
}
throw error;
} Prevention
- Treat contract snapshots as CLI-authored artifacts; never edit them by hand.
- Re-emit snapshots via `pnpm build` / contract-space tooling after schema changes.
- Re-generate snapshots rather than merging conflicting JSON during rebases.
- Run `pnpm fixtures:check` before upgrade scripts.
When it happens
Trigger: Running the codemod against a `migrations/` tree containing a `start-contract.json`/`end-contract.json` that is not valid JSON: trailing comma, unquoted key, comment, BOM, truncation, or merge-conflict markers.
Common situations: Unresolved git merge/rebase conflict markers inside a committed contract snapshot; an interrupted CLI write left a truncated snapshot; a hand-edited snapshot with JSON5 syntax; a `.jsonc` accidentally committed as `.json`.
Related errors
- ${manifestPath}: not valid JSON (${error instanceof Error ?
- ${manifestPath}: manifest is not a JSON object
- ${path}: not valid JSON (${error instanceof Error ? error.me
- ${manifestPath}: manifest is missing a string `migrationHash
- ${filePath}: storage.types[${JSON.stringify(name)}] is neith
AI-assisted analysis of prisma/prisma@1243cdffbe (2026-08-01).
Data as JSON: /data/errors/3f5fddd46c7cfa76.json.
Report an issue: GitHub.