Skip to content

[Bug?]: Portal dependendency on package using workspace protocol fails. #5114

Open
@CodeWitchBella

Description

@CodeWitchBella

Self-service

  • I'd be willing to implement a fix

Describe the bug

Portal dependency on package from a workspace fails with following error:

➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: b@workspace:*: Workspace not found (b@workspace:*)
    at Project.getWorkspaceByDescriptor (/sandbox/berry/packages/yarnpkg-core/sources/Project.ts:506:13)
    at WorkspaceResolver.getCandidates (/sandbox/berry/packages/yarnpkg-core/sources/WorkspaceResolver.ts:41:36)
    at MultiResolver.getCandidates (/sandbox/berry/packages/yarnpkg-core/sources/MultiResolver.ts:45:27)
    at MultiResolver.getCandidates (/sandbox/berry/packages/yarnpkg-core/sources/MultiResolver.ts:45:27)
    at fn (/sandbox/berry/packages/yarnpkg-core/sources/Project.ts:817:33)
    at Object.prettifyAsyncErrors (/sandbox/berry/packages/yarnpkg-core/sources/miscUtils.ts:174:18)
    at startDescriptorResolution (/sandbox/berry/packages/yarnpkg-core/sources/Project.ts:816:54)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 116ms

To reproduce

const {mkdir, writeFile} = require(`fs/promises`);

await mkdir(`workspace`);
await mkdir(`workspace/packages`);
await mkdir(`workspace/packages/a`);
await mkdir(`workspace/packages/b`);
await mkdir(`c`);

await writeFile(`workspace/package.json`, JSON.stringify({
  "workspaces": ["packages/*"],
}));

await writeFile(`workspace/packages/a/package.json`, JSON.stringify({
    name: `a`,
}));

await writeFile(`workspace/packages/b/package.json`, JSON.stringify({
    name: `b`,
    dependencies: {
        b: `workspace:*`,
    },
}));

await writeFile(`c/package.json`, JSON.stringify({
    name: `c`,
    dependencies: {
        b: `portal:../workspace/packages/b`,
    },
}));

await expect(yarn({cwd: `c`})).resolves.toBeTruthy();

Environment

System:
    OS: Linux 6.0 Fedora Linux 37 (Workstation Edition)
    CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
  Binaries:
    Node: 18.12.1 - /tmp/xfs-d8db7e7b/node
    Yarn: 3.3.0 - /tmp/xfs-d8db7e7b/yarn
    npm: 8.19.2 - /usr/bin/npm

Additional context

I am not sure if this is supposed to work and therefore is a bug, so some context on what I am trying to achieve:
I have a project A written in react. And a package B-react, which also depends react and on another framework-agnostic package B-universal, which both reside in a monorepo. This monorepo is a yarn workspace and uses yarn's PnP. A uses node-modules linker.
The thing I want to do is to test a change which requires changing both B-universal and B-react in my application A. And this change is non-trivial and therefore it is not possible to directly publish it to npm - I need to somehow link my projects.

Ofc, there are workarounds like using yarn pack and pointing resolutions to resulting tarballs or using unplug. But I would very much like to be able to directly work in my original repository so that there is no extra step to get the changes into my app nor to commiting the changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreproducibleThis issue can be successfully reproduced

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions