{"record":{"id":"840bf8f3429243f3","repo":"mastra-ai/mastra","slug":"plugin-at-pluginroot-must-declare-an-exact-pnpm","errorCode":null,"errorMessage":"Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".","messagePattern":"Plugin at (.+?) must declare an exact pnpm version in package\\.json using \"packageManager\": \"pnpm@x\\.y\\.z\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/plugins/dependencies.ts","lineNumber":104,"sourceCode":"  while (isInsideDirectory(current, root)) {\n    if (fs.existsSync(path.join(current, 'package.json'))) {\n      return current;\n    }\n    if (current === root) break;\n    current = path.dirname(current);\n  }\n\n  return undefined;\n}\n\nfunction isInsideDirectory(targetPath: string, root: string): boolean {\n  const resolvedTarget = path.resolve(targetPath);\n  const resolvedRoot = path.resolve(root);\n  return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction getPnpmVersion(pluginRoot: string, packageManager: unknown): string {\n  if (typeof packageManager !== 'string') {\n    throw new Error(\n      `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n    );\n  }\n\n  const match = /^pnpm@(\\d+\\.\\d+\\.\\d+)$/.exec(packageManager);\n  if (!match?.[1]) {\n    throw new Error(\n      `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n    );\n  }\n  return match[1];\n}\n\nfunction getInstallCommand(pluginRoot: string, pnpmVersion: string): InstallCommand {\n  const installArgs = ['install', '--ignore-workspace'];\n  if (hasFile(pluginRoot, 'pnpm-lock.yaml')) installArgs.push('--frozen-lockfile');\n  installArgs.push('--ignore-scripts');","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/plugins/dependencies.ts#L86-L122","documentation":"getPnpmVersion requires the plugin's package.json to pin an exact pnpm version via the `packageManager` field. This throw fires when the field is missing or is not a string. The exact version is needed so dependency installation is reproducible across machines.","triggerScenarios":"Calling pnpmVersion (via getPnpmVersion) for a plugin whose package.json either has no `packageManager` key or whose value is not a string (e.g. null after JSON parse, or a non-string value).","commonSituations":"Plugin authors forgot to add `packageManager`; the field was stripped by a publish step; hand-edited package.json with a malformed value.","solutions":["Add `\"packageManager\": \"pnpm@<exact-version>\"` (e.g. `pnpm@9.12.0`) to the plugin's package.json.","Run `corepack use pnpm@latest` in the plugin directory to set the field automatically.","Commit the updated package.json and reinstall the plugin."],"exampleFix":"// before: plugin package.json\n{\n  \"name\": \"my-plugin\"\n}\n\n// after\n{\n  \"name\": \"my-plugin\",\n  \"packageManager\": \"pnpm@9.12.0\"\n}","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nexport function assertPinnedPnpm(pluginRoot: string): void {\n  const pkg = JSON.parse(fs.readFileSync(`${pluginRoot}/package.json`, 'utf8'));\n  const pm = pkg.packageManager;\n  if (typeof pm !== 'string' || !/^pnpm@\\d+\\.\\d+\\.\\d+$/.test(pm)) {\n    throw new Error(`${pluginRoot}: add \"packageManager\": \"pnpm@x.y.z\" to package.json`);\n  }\n}","typeGuard":"function isPinnedPnpm(v: unknown): v is `pnpm@${number}.${number}.${number}` {\n  return typeof v === 'string' && /^pnpm@\\d+\\.\\d+\\.\\d+$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Always initialize plugins with `corepack use pnpm@<version>` so the field is written for you.","Add a lint/CI check asserting packageManager matches /^pnpm@\\d+\\.\\d+\\.\\d+$/.t","Never hand-edit or strip the packageManager field in publish scripts."],"tags":["pnpm","package-json","configuration","plugins"],"backgroundTag":"missing-package-manager-field","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}