{"record":{"id":"f8e0a54f19a2c775","repo":"mastra-ai/mastra","slug":"could-not-determine-project-name-from-package-json-f8e0a5","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":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/server/deploy.ts","lineNumber":288,"sourceCode":"      }\n    }\n\n    const created = await createServerProject(token, orgId, flagProject);\n    p.log.success(`Created project \"${created.name}\"`);\n    return { projectId: created.id, projectName: created.name, projectSlug: created.slug ?? created.name };\n  }\n\n  if (projectConfig?.projectId && projectConfig.organizationId === orgId) {\n    return {\n      projectId: projectConfig.projectId,\n      projectName: projectConfig.projectName ?? projectConfig.projectId,\n      projectSlug: projectConfig.projectSlug ?? projectConfig.projectName ?? projectConfig.projectId,\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  const existing = await fetchServerProjects(token, orgId);\n  const nameMatches = existing.filter(proj => proj.name === name || proj.slug === name);\n\n  if (existing.length > 0) {\n    if (autoAccept) {\n      // Non-interactive: only safe to auto-pick when exactly one project matches by name/slug.\n      if (nameMatches.length === 1) {\n        const m = nameMatches[0]!;\n        return { projectId: m.id, projectName: m.name, projectSlug: m.slug ?? m.name };\n      }\n      throw new Error(\n        `Found ${existing.length} existing project(s) in this organization. Pass --project <id-or-slug> to select one, or re-run without --yes to choose interactively.`,\n      );\n    }\n\n    const CREATE_NEW = '__create_new__';","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/server/deploy.ts#L270-L306","documentation":"`mastra server deploy` needs a project name when it falls back to creating/auto-selecting a project. resolveProject derives that default name from package.json (e.g. the package name); when no --project flag, MASTRA_PROJECT_ID env var, or linked .mastra-project.json project is available AND package.json yields no usable name, it throws so it doesn't create a nameless project.","triggerScenarios":"Running `mastra server deploy` (with or without --yes) in a directory where: package.json is missing or unreadable, its `name` field is empty/invalid, and none of MASTRA_PROJECT_ID, --project, or a matching .mastra-project.json (projectId with matching organizationId) is set.","commonSituations":"Deploying from a workspace root or scratch directory without package.json; a monorepo sub-package with an empty \"name\"; CI job that checks out only a subfolder; user assumes .mastra-project.json exists but it was gitignored/deleted or was written for a different org (organizationId mismatch makes it ignored).","solutions":["Pass an explicit project: `mastra server deploy --project <id-or-slug-or-new-name>`","Set MASTRA_PROJECT_ID in the environment before deploying","Add a valid non-empty \"name\" field to package.json in the deploy directory","Deploy from the directory containing a .mastra-project.json linked to the correct organization (matching organizationId)"],"exampleFix":"// before (package.json)\n{ \"private\": true }\n// after\n{ \"name\": \"my-mastra-app\", \"private\": true }","handlingStrategy":"validation","validationCode":"import { readFile } from 'node:fs/promises';\nexport async function assertProjectNameResolvable(dir: string, opts: { project?: string } = {}) {\n  if (process.env.MASTRA_PROJECT_ID || opts.project) return;\n  try {\n    const pkg = JSON.parse(await readFile(`${dir}/package.json`, 'utf-8'));\n    if (typeof pkg.name === 'string' && pkg.name.trim()) return;\n  } catch {}\n  throw new Error(`No project name resolvable in ${dir}. Pass --project or fix package.json \"name\".`);\n}","typeGuard":"function hasProjectName(pkg: unknown): pkg is { name: string } {\n  return typeof pkg === 'object' && pkg !== null &&\n    typeof (pkg as any).name === 'string' && (pkg as any).name.trim().length > 0;\n}","tryCatchPattern":"try {\n  await run(['mastra', 'server', 'deploy', '--project', projectName]);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Could not determine project name')) {\n    console.error('Set package.json \"name\" or pass --project <id-or-slug>');\n  }\n  throw err;\n}","preventionTips":["Always keep a non-empty \"name\" in package.json of deployable packages","In CI, always pass --project or set MASTRA_PROJECT_ID explicitly","Commit .mastra-project.json (or generate it in CI) so deploys are linked","Run the deploy from the package directory, not the workspace root"],"tags":["cli","config","project-resolution"],"backgroundTag":"missing-project-name","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}