{"record":{"id":"892ac49a0b63c9df","repo":"pnpm/pnpm","slug":"cannotresolveworkspaceprotocolerror","errorCode":null,"errorMessage":"CannotResolveWorkspaceProtocolError","messagePattern":"CannotResolveWorkspaceProtocolError","errorType":"exception","errorClass":"ReplaceWorkspaceProtocolError","httpStatus":null,"severity":"error","filePath":"pnpm/crates/exportable-manifest/src/replace.rs","lineNumber":44,"sourceCode":"#[derive(Debug, Display, Error, Diagnostic, Clone)]\n#[display(\n    \"Cannot resolve workspace protocol of dependency \\\"{dep_name}\\\" \\\n     because this dependency is not installed. Try running \\\"pnpm install\\\".\"\n)]\n#[diagnostic(code(ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL))]\npub struct CannotResolveWorkspaceProtocolError {\n    #[error(not(source))]\n    pub dep_name: String,\n}\n\n/// Error envelope for both rewrite helpers.\n#[derive(Debug, Display, Error, Diagnostic)]\npub enum ReplaceWorkspaceProtocolError {\n    /// The dependency's directory was found but the `package.json`\n    /// lacked one of the required fields. Most common reason: the\n    /// project hasn't been installed yet.\n    #[diagnostic(transparent)]\n    CannotResolve(#[error(source)] CannotResolveWorkspaceProtocolError),\n\n    /// Reading `<dep>/package.json` itself failed (malformed JSON, IO\n    /// error other than ENOENT, ...). Propagated so the caller can\n    /// surface the underlying cause.\n    ReadManifest(#[error(source)] PackageManifestError),\n}\n\n/// Rewrites a single `dependencies` / `devDependencies` /\n/// `optionalDependencies` value at publish time.\n///\n/// Returns `dep_spec` unchanged when it doesn't start with `workspace:`\n/// so the caller can fold the helper into a generic per-field rewrite\n/// without branching on the protocol.\npub fn replace_workspace_protocol(\n    dep_name: &str,\n    dep_spec: &str,\n    dir: &Path,\n    modules_dir: Option<&Path>,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/pnpm/pnpm/blob/e45f0332229b094d61f2ecad114a166e338c0d61/pnpm/crates/exportable-manifest/src/replace.rs#L26-L62","documentation":"This variant wraps `CannotResolveWorkspaceProtocolError` and is thrown by the exportable-manifest crate when rewriting `workspace:` dependency ranges into publishable versions. It fires when the dependency's directory was located, but its `package.json` lacked one of the fields required to derive the published version (name/version). Per the source docs, the most common reason is that the workspace project has not been installed yet, so the manifest fields pnpm relies on are absent.","triggerScenarios":"Calling the workspace-protocol replacement during `pnpm publish`/`pack` for a dependency whose spec starts with `workspace:` while the referenced workspace package's manifest cannot yield the resolved version (missing name/version fields or missing manifest content).","commonSituations":"Publishing a freshly cloned monorepo without running `pnpm install` first; a workspace package with a hand-edited or incomplete `package.json`; a `workspace:` dependency pointing at a project whose manifest was generated or stripped.","solutions":["Run `pnpm install` in the workspace root before publishing so every referenced project's manifest is fully populated.","Check that `<dep>/package.json` contains the required fields (name, version) for the dependency referenced with `workspace:`.","Verify the `workspace:` specifier points at a real workspace project (correct path/name in `pnpm-workspace.yaml` globs).","Re-run the publish/pack command after fixing the manifest."],"exampleFix":"// before: publish without installing\npnpm publish\n\n// after: install first so workspace manifests are resolved\npnpm install\npnpm publish","handlingStrategy":"validation","validationCode":"// before resolving workspace: specs, ensure the dep manifest is complete\nconst manifest = JSON.parse(fs.readFileSync(path.join(depDir, 'package.json'), 'utf8'))\nif (!manifest.name || !manifest.version) {\n  throw new Error(`${depDir}/package.json is missing name/version — run pnpm install first`)\n}","typeGuard":"function isWorkspaceSpec(spec: string): boolean {\n  return typeof spec === 'string' && spec.startsWith('workspace:')\n}","tryCatchPattern":"try {\n  await replaceWorkspaceProtocol(manifest)\n} catch (err) {\n  if (err.code === 'ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL') {\n    console.error(`Run pnpm install before publishing: ${err.message}`)\n    process.exit(1)\n  }\n  throw err\n}","preventionTips":["Always run pnpm install before pnpm publish/pack in a workspace","Validate all workspace package.json files in CI (name and version present)","Keep workspace globs in pnpm-workspace.yaml in sync with the actual directories"],"tags":["workspace","publish","manifest"],"backgroundTag":"workspace-protocol-unresolvable","analyzedSha":"e45f0332229b094d61f2ecad114a166e338c0d61","analyzedAt":"2026-09-22T05:07:20.233Z","contentChangedAt":"2026-09-22T05:07:20.233Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}