berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug] Resolver does not work with alias without range

Open ikatyang opened this issue 5 years ago • 3 comments

Describe the bug

Resolver does not work with alias without range, alias should work the same way as normal dependencies, i.e.,

  • yarn add typescript will be resolved as "typescript": "^X.Y.Z", so that
  • yarn add alias@npm:typescript should be resolved as "alias": "npm:typescript@^X.Y.Z"

To Reproduce

  • unscoped:

    await packageJsonAndInstall({});
    await expect(yarn(`add`, `alias@npm:typescript`)).resolves.toBeTruthy();
    // Error: alias@npm:typescript: Registry failed to return tag "typescript"
    
  • scoped:

    await packageJsonAndInstall({});
    await expect(yarn(`add`, `alias@npm:@babel/core`)).resolves.toBeTruthy();
    // Error: alias@npm:@babel/core isn't supported by any available resolver
    

Environment

  • Yarn version 2.2.2

Additional context

ikatyang avatar Sep 07 '20 15:09 ikatyang

This issue reproduces on master:

Error: expect(received).resolves.toBeTruthy()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js add alias@npm:@babel/core

➤ YN0000: ┌ Resolution step
::group::Resolution step
➤ YN0001: │ Error: alias@npm:@babel/core isn't supported by any available resolver
    at MultiResolver.getResolverByDescriptor (/github/workspace/packages/yarnpkg-core/sources/MultiResolver.ts:73:13)
    at MultiResolver.bindDescriptor (/github/workspace/packages/yarnpkg-core/sources/MultiResolver.ts:31:27)
    at /github/workspace/packages/yarnpkg-core/sources/Project.ts:824:34
    at async Promise.all (index 0)
    at Project.resolveEverything (/github/workspace/packages/yarnpkg-core/sources/Project.ts:801:35)
    at /github/workspace/packages/yarnpkg-core/sources/Project.ts:1499:7
    at StreamReport.startTimerPromise (/github/workspace/packages/yarnpkg-core/sources/StreamReport.ts:249:14)
    at Project.install (/github/workspace/packages/yarnpkg-core/sources/Project.ts:1482:5)
    at /github/workspace/packages/plugin-essentials/sources/commands/add.ts:279:7
    at Function.start (/github/workspace/packages/yarnpkg-core/sources/StreamReport.ts:133:7)
::endgroup::
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 114ms
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0ac41999f0.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:3:7)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-63f998598d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-63f998598d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-63f998598d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-63f998598d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-a57989414f.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-a57989414f.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-a57989414f.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)

yarnbot avatar Sep 07 '20 15:09 yarnbot

Ran into this same issue while installing TailwindCSS with Yarn 2 https://github.com/tailwindlabs/tailwindcss/issues/3432

$ yarn add tailwindcss@npm:@tailwindcss/postcss7-compat
➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: tailwindcss@npm:@tailwindcss/postcss7-compat isn't supported by any available resolver
    at n.getResolverByDescriptor (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:336683)
    at n.bindDescriptor (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:336048)
    at d (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:357409)
    at async Promise.all (index 0)
    at async ie.resolveEverything (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:358614)
    at async /Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:377271
    at async f.startTimerPromise (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:389740)
    at async ie.install (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:377210)
    at async /Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:33217
    at async Function.start (/Users/someone/a-react-app/.yarn/releases/yarn-berry.cjs:2:388437)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 110ms

Thanks for the workaround, @ikatyang On Yarn 2.4.0 after specifying the version tag, tailwindCSS works with yarn 2 🙇

sshquack avatar Jan 29 '21 19:01 sshquack

Still reproducible on Yarn 4.6.0. Ran into it while installing @looker/embed-sdk which depends on a package through an alias: npm:@types/web.

Because it's a sub-dependency causing the issue, had to add resolutions to the package.json to work around it as suggested here:

"resolutions": {
    "@typescript/lib-dom": "npm:@types/web@*"
  }

Note that if you use workspaces, the resolutions must be defined in the root package.json regardless of where the package is installed.

JustasStarred avatar Apr 30 '25 09:04 JustasStarred