{"record":{"id":"effb5423f3c61438","repo":"mastra-ai/mastra","slug":"could-not-determine-project-name-from-package-json","errorCode":null,"errorMessage":"Could not determine project name from package.json. Use --project to specify one.","messagePattern":"Could not determine project name from package\\.json\\. Use --project to specify one\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/deploy/index.ts","lineNumber":263,"sourceCode":"        })),\n        { value: CREATE_NEW, label: defaultName ? `＋ Create new project \"${defaultName}\"` : '＋ Create new project' },\n      ],\n    });\n\n    if (p.isCancel(selected)) {\n      p.cancel('Deploy cancelled.');\n      process.exit(0);\n    }\n\n    if (selected !== CREATE_NEW) {\n      const match = projects.find(proj => proj.id === selected)!;\n      return { existing: true, projectId: match.id, projectName: match.name, projectSlug: match.slug ?? match.name };\n    }\n  }\n\n  const name = defaultName;\n  if (!name) {\n    throw new Error('Could not determine project name from package.json. Use --project to specify one.');\n  }\n\n  return { existing: false, projectName: name };\n}\n\n/* ------------------------------------------------------------------ */\n/*  Resolve environment                                               */\n/* ------------------------------------------------------------------ */\n\ntype EnvironmentResolution =\n  | { existing: true; environment: Environment }\n  | { existing: false; name: string; type: 'production' | 'staging' | 'preview' };\n\nasync function resolveEnvironment(\n  token: string,\n  orgId: string,\n  projectId: string,\n  envName: string,","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/deploy/index.ts#L245-L281","documentation":"resolveProject needs a name for a NEW project when none exists and no --project was given. It falls back to `defaultName` (derived from package.json); when that is absent it throws, directing you to pass --project. The CLI refuses to invent a project name because the name determines identity/matching of the deployed project.","triggerScenarios":"Deploy where the org has no matching existing project, no --project supplied, and defaultName is empty — typically because package.json is missing or has no `name` field (common in workspaces, bare directories, or generated build dirs).","commonSituations":"Deploying from a directory whose package.json lacks a name; monorepo root package.json without a name; running deploy from a subfolder with no package.json at all.","solutions":["Add a `name` field to package.json in the deploy directory","Pass --project <name> explicitly to name the new project","Run the deploy from the correct package directory if you invoked it from the workspace root","Set the package.json name to match the intended existing project if one already exists"],"exampleFix":"// before\n// package.json\n{ \"private\": true }\n// after\n{ \"private\": true, \"name\": \"my-service\" }","handlingStrategy":"validation","validationCode":"import { readFileSync, existsSync } from 'node:fs';\nconst pkgPath = 'package.json';\nif (!existsSync(pkgPath)) throw new Error('No package.json in deploy directory');\nconst pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string };\nif (!pkg.name) throw new Error('package.json is missing \"name\"; add it or pass --project');","typeGuard":"function hasPackageName(pkg: { name?: string }): pkg is { name: string } {\n  return typeof pkg.name === 'string' && pkg.name.length > 0;\n}","tryCatchPattern":"try {\n  await deploy(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Could not determine project name')) {\n    console.error('Add a name to package.json or pass --project <name>');\n  } else throw err;\n}","preventionTips":["Ensure every deployable package has a `name` in package.json","Run deploys from the package directory, not a bare workspace root","In monorepos, script deploys per-package with explicit --project","Lint package.json for required fields in CI before deploy"],"tags":["configuration","package-json","deploy","cli"],"backgroundTag":"missing-package-name","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}