mastra-ai/mastra · error · Error

Presets file not found: ${absolutePath}

Error message

Presets file not found: ${absolutePath}

What it means

loadAndValidatePresets() resolves the given presets path against process.cwd() and throws immediately if the file does not exist on disk. The CLI's dev and studio commands call it when a presets file is supplied, so this error means the path you passed (e.g. via --presets) could not be found. It surfaces the fully resolved absolute path so you can see exactly where the CLI looked.

Source

Thrown at packages/cli/src/utils/validate-presets.ts:16

import { existsSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';

/**
 * Loads and validates a request context presets JSON file.
 *
 * @param presetsPath - Path to the presets JSON file (relative or absolute)
 * @returns The original JSON string content
 * @throws Error if file doesn't exist, JSON is invalid, or structure is incorrect
 */
export async function loadAndValidatePresets(presetsPath: string): Promise<string> {
  const absolutePath = resolve(process.cwd(), presetsPath);

  if (!existsSync(absolutePath)) {
    throw new Error(`Presets file not found: ${absolutePath}`);
  }

  const content = await readFile(absolutePath, 'utf-8');

  let parsed: unknown;
  try {
    parsed = JSON.parse(content);
  } catch {
    throw new Error(`Invalid JSON in presets file: ${presetsPath}`);
  }

  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
    throw new Error(`Presets file must contain a JSON object with named presets`);
  }

  // Validate each preset value is an object
  for (const [key, value] of Object.entries(parsed)) {
    if (typeof value !== 'object' || value === null || Array.isArray(value)) {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the resolved absolute path in the error message exists: ls <absolutePath>.
  2. Run the command from the project root or pass an absolute path to the presets file.
  3. Fix typos in the file name/extension and confirm the file is not gitignored/missing in CI.

Example fix

// before
mastra dev --presets ./config/presets.json  // file is at ./configs/presets.json
// after
mastra dev --presets ./configs/presets.json
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync, statSync } from 'node:fs';
import { resolve } from 'node:path';
function validatePresetsFile(path: string): string | null {
  const abs = resolve(process.cwd(), path);
  if (!existsSync(abs)) return `Presets file not found: ${abs}`;
  if (!statSync(abs).isFile()) return `Not a file: ${abs}`;
  return null;
}

Try / catch

try {
  await loadAndValidatePresets(presetsPath);
} catch (err) {
  if ((err as Error).message.startsWith('Presets file not found')) {
    console.error(`Check --presets path (resolved against cwd=${process.cwd()}): ${(err as Error).message}`);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `mastra dev` or `mastra studio` with a presets file flag/path that does not exist, or running the command from a different working directory so a relative path no longer resolves.

Common situations: Typo in the file name or extension (e.g. .jsonc instead of .json), running the CLI from a subdirectory so relative paths break, CI checkout missing a gitignored presets file, or the file was renamed/deleted.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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