8000 building dist for publishing with workspace protocol cannot resolve · Issue #9495 · pnpm/pnpm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

building dist for publishing with workspace protocol cannot resolve #9495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
zacharykane opened this issue May 6, 2025 · 2 comments
Open
1 of 4 tasks

Comments

@zacharykane
Copy link
zacharykane commented May 6, 2025

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

10.5.2

Which area(s) of pnpm are affected? (leave empty if unsure)

Lockfile, Workspaces

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

  • setup pnpm workspaces as fairly typical
    // pnpm-workspace.yml
    packages:
      - packages/*
    
  • configure each package with a dependency on another workspace package
    "dependencies": {
      "@scope/another": "workspace:^"
    }
    
  • configure a build process to generate dist directories within each package
    • this also creates a near-duplicate package.json file in that new directory, still containing workspace: protocol version declarations
  • run a pnpm -r publish

Describe the Bug

When using the Workspaces feature, we need a way to resolve the workspace:^ protocol in package.jsons when they are within the generated built files after a build process. Given the reproduction setup, running pnpm publish within a packages/**/dist directory results in the following error:

ERR_PNPM_CANNOT_RESOLVE_WORKSPACE_PROTOCOL
Cannot resolve workspace protocol of dependency "@scope/mine" because the dependency is not installed. Try running "pnpm install"

However, this seems to be because the directory packages/**/dist is not declared as a workspace. That in and of itself makes sense, however how am I meant to proceed with a simple publishing process once I have a dist directory? I do not want to publish an entire packages/** directory, as that is Typescript and configuration files that have no business being distributed (nor would my users be able to easily navigate to the proper entry points with so many index.* files around).

I have tried the publishConfig.directory approach, which allows me to work within a packages/** directory as a workspace, and get publish or pack to replace the semvers. However this introduces another complexity in that now the dist directories are necessary at all times for importing during development, since the linked node_modules are now all looking for them. (I can see this as my pnpm-lock.yml updates to start pointing to all of the dists.)

I'd also prefer not to have some build:watch process, in addition to storybook running, to allow all of my workspace packages to talk to one another... but is that the only solution?

Expected Behavior

pnpm workspaces can understand the concept of a built directory, within a package workspace directory and accomplish resolving the workspace: protocol version numbers, while also not creating hard dependencies on the same generated directories during normal development.

Which Node.js version are you using?

22.12.0

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

@NaceurBouhamed
Copy link

+1
Ccurrently having these exact issues.
Some temporary solution can be adding these options the .npmrc and removing the "workspace:" from your packages.jon

link-workspace-packages = true
prefer-workspace-packages = true

Although, this comes with some performance hits to the ci

@NaceurBouhamed
Copy link
NaceurBouhamed commented May 13, 2025

Solved on my side by adding "linkDirectory": false option in the publishConfig, and generating a new pnpm-lock.yaml file
https://pnpm.io/package_json#publishconfiglinkdirectory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0