mastra-ai/mastra · error · Error

Could not determine project name from package.json. Use --pr

Error message

Could not determine project name from package.json. Use --project to specify one.

What it means

When the deploy flow decides a new project must be created, it derives the project name from the local package.json `name` field. If that value is missing (no name, or no readable package.json), the command cannot name the project and throws, telling you to supply one via --project.

Source

Thrown at packages/cli/src/commands/studio/deploy.ts:358

      ],
    });

    if (p.isCancel(selected)) {
      p.cancel('Deploy cancelled.');
      process.exit(0);
    }

    if (selected !== CREATE_NEW) {
      const match = projects.find(proj => proj.id === selected)!;
      return { existing: true, projectId: match.id, projectName: match.name, projectSlug: match.slug ?? match.name };
    }
    // fall through to create-new flow
  }

  // 4. No existing project (or user chose "Create new") — return the name so caller can create after confirmation.
  const name = defaultName;
  if (!name) {
    throw new Error('Could not determine project name from package.json. Use --project to specify one.');
  }

  return { existing: false, projectName: name };
}

/* ------------------------------------------------------------------ */
/*  Main deploy action                                                */
/* ------------------------------------------------------------------ */

type StudioDeployOptions = {
  org?: string;
  project?: string;
  yes?: boolean;
  config?: string;
  skipBuild?: boolean;
  skipPreflight?: boolean;
  debug?: boolean;
  envFile?: string;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass the name explicitly: `mastra studio deploy --project my-project-name`
  2. Add a `name` field to package.json in the deploy directory
  3. Run the command from the directory containing the correct package.json
  4. If a project already exists, target it with --project <id-or-slug> to skip the create-new flow

Example fix

// before (package.json)
{ "version": "1.0.0" }
// Error: Could not determine project name from package.json.
// after
{ "name": "my-mastra-app", "version": "1.0.0" }
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'node:fs';
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
if (typeof pkg.name !== 'string' || pkg.name.length === 0) {
  throw new Error('package.json has no name; pass --project <name> to deploy.');
}

Type guard

function hasProjectName(pkg: unknown): pkg is { name: string } {
  return typeof pkg === 'object' && pkg !== null && 'name' in pkg && typeof (pkg as { name?: unknown }).name === 'string' && (pkg as { name: string }).name.length > 0;
}

Try / catch

try {
  await studioDeploy();
} catch (e) {
  if (e instanceof Error && e.message.includes('Could not determine project name from package.json')) {
    console.error('Add a name to package.json or pass --project <name>.');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Running `mastra studio deploy` in a directory without package.json, or with a package.json lacking a `name` field, when no existing project was matched/selected (create-new path reached).

Common situations: Deploying from a scratch directory or a package-less workspace; a monorepo root package.json with no name; typos like "naem" in package.json; deploying an app initialized outside npm/pnpm conventions.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/522ec9032b6e411e. Report an issue: GitHub.