mastra-ai/mastra · error
Failed to run install command with swpm and native package m
Error message
Failed to run install command with swpm and native package managers
What it means
spawnSWPM attempts the swpm-managed install first and falls back to the detected native package manager (npm/pnpm/yarn/bun). If BOTH invocations fail — spawn throws on both attempts — it throws 'Failed to run install command with swpm and native package managers'. Each failure is warned to console, so the underlying causes are in the preceding warnings.
Source
Thrown at packages/agent-builder/src/utils.ts:205
} else if (packageManager === 'npm') {
args.push('--yes'); // npm install --yes
// Check if we're in a workspace subfolder
if (inWorkspace) {
args.push('--ignore-workspaces');
}
}
}
args.push(...packageNames);
console.info(`Falling back to ${packageManager} ${args.join(' ')}`);
await spawn(packageManager, args, { cwd });
return;
} catch (e) {
console.warn(`Failed to run install command with native package manager: ${e}`);
}
throw new Error(`Failed to run install command with swpm and native package managers`);
}
// Utility functions
export function kindWeight(kind: UnitKind): number {
const idx = UNIT_KINDS.indexOf(kind as any);
return idx === -1 ? UNIT_KINDS.length : idx;
}
// Utility functions to work with Mastra templates
export async function fetchMastraTemplates(): Promise<
Array<{
slug: string;
title: string;
description: string;
githubUrl: string;
tags: string[];
agents: string[];
workflows: string[];View on GitHub (pinned to 75dd419e61)
Solutions
- Read the two preceding console.warn lines to see the native error, then fix that root cause (missing binary, bad path, auth)
- Install the native package manager on PATH (e.g. `npm i -g pnpm`) or point PATH at it
- Verify the cwd passed to spawnSWPM exists and is a valid package directory (has package.json or can be initialized)
- Retry the install after fixing network/registry access; check registry URL and tokens in .npmrc
- If swpm itself is broken, ensure it is installed/up to date so the primary attempt can succeed
Example fix
// before
await spawnSWPM('pnpm', ['add', 'zod'], nonExistentDir);
// after
import { existsSync } from 'node:fs';
if (!existsSync(targetDir)) throw new Error(`Target dir ${targetDir} does not exist`);
await spawnSWPM('pnpm', ['add', 'zod'], targetDir); Defensive patterns
Strategy: try-catch
Validate before calling
import { existsSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
if (!existsSync(cwd)) throw new Error(`cwd does not exist: ${cwd}`);
execFileSync('npm', ['--version']); // ensures a native PM is on PATH Try / catch
try {
await installPackages(packages, cwd);
} catch (e) {
if (e instanceof Error && e.message.includes('swpm and native package managers')) {
// inspect the earlier console.warn output for the native spawn failure and fix PATH/cwd/registry
} else throw e;
} Prevention
- Ensure npm/pnpm/yarn/bun is installed and on PATH in the environment running the builder
- Validate the target directory exists and contains package.json before installing
- Check registry/auth configuration (.npmrc) in CI and containers
- Capture the per-attempt console.warn output for root-cause diagnosis
When it happens
Trigger: installPackages/upgradePackages/installStep calling spawnSWPM in a directory where the swpm spawn fails (non-zero exit, missing binary) AND the fallback native package manager spawn also fails (binary not installed, bad cwd, network/auth failure on install).
Common situations: Scaffolding a project on a machine without npm/pnpm on PATH; invalid cwd (targetPath doesn't exist); private registry auth failures; offline environments; corrupted lockfiles making every install attempt exit non-zero.
Related errors
- NODE_FAIL_INSTALL_SPECIFIED_VERSION
- FAIL_INSTALL_DEPS
- FAIL_CUSTOM_INSTALL_COMMAND
- Failure in install step: ${installResult.error || 'Install f
- DEPLOYER_PNPM_IGNORED_BUILDS
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/651745b4e4279e72.
Report an issue: GitHub.