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

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.

Source

Thrown at packages/cli/src/commands/deploy/index.ts:263

        })),
        { value: CREATE_NEW, label: defaultName ? `+ Create new project "${defaultName}"` : '+ Create new project' },
      ],
    });

    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 };
    }
  }

  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 };
}

/* ------------------------------------------------------------------ */
/*  Resolve environment                                               */
/* ------------------------------------------------------------------ */

type EnvironmentResolution =
  | { existing: true; environment: Environment }
  | { existing: false; name: string; type: 'production' | 'staging' | 'preview' };

async function resolveEnvironment(
  token: string,
  orgId: string,
  projectId: string,
  envName: string,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Add a `name` field to package.json in the deploy directory
  2. Pass --project <name> explicitly to name the new project
  3. Run the deploy from the correct package directory if you invoked it from the workspace root
  4. Set the package.json name to match the intended existing project if one already exists

Example fix

// before
// package.json
{ "private": true }
// after
{ "private": true, "name": "my-service" }
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync, existsSync } from 'node:fs';
const pkgPath = 'package.json';
if (!existsSync(pkgPath)) throw new Error('No package.json in deploy directory');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { name?: string };
if (!pkg.name) throw new Error('package.json is missing "name"; add it or pass --project');

Type guard

function hasPackageName(pkg: { name?: string }): pkg is { name: string } {
  return typeof pkg.name === 'string' && pkg.name.length > 0;
}

Try / catch

try {
  await deploy(opts);
} catch (err) {
  if (err instanceof Error && err.message.includes('Could not determine project name')) {
    console.error('Add a name to package.json or pass --project <name>');
  } else throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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