{"record":{"id":"54998f3a22c8c6e9","repo":"mastra-ai/mastra","slug":"err-instanceof-error-err-message-string-err","errorCode":null,"errorMessage":"${err instanceof Error ? err.message : String(err)}\\nYou can retry manually: cd ${projectName} && ${packageManager} install","messagePattern":"(.+?)\\\\nYou can retry manually: cd (.+?) && (.+?) install","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/mastra-factory/src/create.ts","lineNumber":131,"sourceCode":"    }\n    spinner.stop('Template downloaded.');\n  } catch (err) {\n    spinner.stop('Template download failed.');\n    throw err;\n  }\n\n  // ── Install dependencies ─────────────────────────────────────────────────\n  const installSpinner = p.spinner();\n  installSpinner.start(`Installing dependencies...`);\n  try {\n    await x(packageManager, getInstallArgs(packageManager), {\n      throwOnError: true,\n      nodeOptions: { cwd: projectPath },\n    });\n    installSpinner.stop('Dependencies installed.');\n  } catch (err) {\n    installSpinner.stop('Dependency install failed.');\n    throw new Error(\n      `${err instanceof Error ? err.message : String(err)}\\nYou can retry manually: cd ${projectName} && ${packageManager} install`,\n    );\n  }\n\n  // ── Platform provisioning ────────────────────────────────────────────────\n  let platformResult: PlatformProvisionResult | null = null;\n  let platformError: string | null = null;\n  let platformSkipped = false;\n  if (!args.noPlatform) {\n    try {\n      platformResult = await runPlatformProvisioning({\n        projectName,\n        projectPath,\n        region: requestedRegion,\n        org: args.org,\n      });\n    } catch (err) {\n      if (err instanceof LoginCancelledError) {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/mastra-factory/src/create.ts#L113-L149","documentation":"The create() command in mastracode/mastra-factory/src/create.ts wraps the dependency-install step (a spawned package-manager process with throwOnError: true) in try/catch. When the install command exits non-zero, the spinner stops with 'Dependency install failed.' and the original error message is re-thrown with a manual-retry hint: cd into the generated project and run the chosen package manager's install yourself.","triggerScenarios":"The spawned `${packageManager} install` in the freshly scaffolded projectPath exits non-zero: no network/registry unreachable, private registry auth missing (NPM_TOKEN), unsupported Node version for a dependency, package manager binary not installed (e.g. pnpm absent), lockfile/platform-specific optional deps failing, or disk/permission errors in the target directory.","commonSituations":"Corporate proxy or offline CI blocking registry.npmjs.org; running the generator in a container without pnpm/yarn installed while the scaffold defaults to it; Node engine mismatch (newer packages requiring Node 20+); postinstall scripts blocked by --ignore-scripts security policy; ratelimited or authenticated npm registry.","solutions":["Follow the hint: cd <projectName> && <packageManager> install — transient network failures often succeed on retry.","Verify the package manager binary exists and is on PATH (e.g. `pnpm --version`); install it or pass a different packageManager choice.","Check network/registry access and auth (NPM_TOKEN, .npmrc, proxy env vars).","Confirm Node version satisfies the generated project's engines field and upgrade if needed.","Clear the package manager cache if corruption is suspected, then rerun install manually."],"exampleFix":"// before: generated project fails install due to missing pnpm\n$ mastra-factory create my-app --package-manager pnpm\nError: spawn pnpm ENOENT\\nYou can retry manually: cd my-app && pnpm install\n// after: ensure the manager exists first\ncommand -v pnpm >/dev/null || npm i -g pnpm\n$ mastra-factory create my-app --package-manager pnpm","handlingStrategy":"try-catch","validationCode":"import { execSync } from 'node:child_process';\n// pre-flight before invoking the generator\ntry { execSync(`${packageManager} --version`, { stdio: 'ignore' }); }\ncatch { throw new Error(`${packageManager} is not installed or not on PATH`); }\nexecSync('curl -sf https://registry.npmjs.org/-/ping', { stdio: 'ignore' }); // registry reachable","typeGuard":null,"tryCatchPattern":"try {\n  await create(args);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.includes('retry manually')) {\n    const [_, projectName, pm] = msg.match(/cd (\\S+) && (\\S+) install/) ?? [];\n    execSync(`cd ${projectName} && ${pm} install`, { stdio: 'inherit' }); // surface real install output\n  } else throw err;\n}","preventionTips":["Pre-install the chosen package manager (pnpm/yarn/npm) and confirm it's on PATH before scaffolding.","Ensure registry access: set NPM_TOKEN/.npmrc and proxy env vars in CI.","Pin a Node version matching the generated project's engines field (use nvm/.nvmrc).","On failure, run the suggested manual install — it shows the real npm/pnpm error the wrapper swallowed."],"tags":["cli","dependency-install","spawn","network","node"],"backgroundTag":"dependency-install-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}