jsr-io / jsr-npm

A cli tool to make installing packages form jsr.io in node easy
https://npmjs.com/package/jsr
MIT License
92 stars 13 forks source link

`yarn dlx jsr add` does not work when following Yarn 2 & jsr basic setup docs #32

Closed nicolo-ribaudo closed 5 months ago

nicolo-ribaudo commented 5 months ago

I created an empty project with Yarn, following Yarn's docs in an empty folder:

corepack enable
yarn init -2

Then, I run yarn dlx jsr add @nic-test/test-log (copy-pasted from the Yarn tab at https://jsr.io/@nic-test/test-log@0.1.0), and I get this output:

➜ yarn dlx jsr add @nic-test/test-log
➤ YN0000: · Yarn 4.1.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + jsr@npm:0.9.0, kolorist@npm:1.8.0, node-stream-zip@npm:1.15.0
➤ YN0000: └ Completed in 0s 567ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 3 packages were added to the project (+ 167.89 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 628ms

Setting up .npmrc...ok
Installing @nic-test/test-log...
$ yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log
➤ YN0000: · Yarn 4.1.0
➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @nic-test/test-log@npm:@jsr/nic-test__test-log isn't supported by any available resolver
    at Dd.getResolverByDescriptor (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:141:1698)
    at Dd.bindDescriptor (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:141:1083)
    at Pt.preparePackage (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:210:6173)
    at async ne (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:210:7583)
    at async Promise.allSettled (index 0)
    at async Uc (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:140:53244)
    at async /Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:210:9140
    at async Nt.startProgressPromise (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:140:137284)
    at async Pt.resolveEverything (/Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:210:7138)
    at async /Users/nic/.cache/node/corepack/yarn/4.1.0/yarn.js:213:2648
➤ YN0000: └ Completed
➤ YN0000: · Failed with errors in 0s 13ms
nicolo-ribaudo commented 5 months ago

I assumed that the problem is that jsr is running yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log instead of yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log@^0.1.0. So I tried manually running yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log@^0.1.0 (yarn dlx jsr already created the .npmrc file), but Yarn is still trying to fetch from the default registry:

➜ yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log@^0.1.0
➤ YN0000: · Yarn 4.1.0
➤ YN0000: ┌ Resolution step
➤ YN0035: │ @nic-test/test-log@npm:@jsr/nic-test__test-log@^0.1.0: Package not found
➤ YN0035: │   Response Code: 404 (Not Found)
➤ YN0035: │   Request Method: GET
➤ YN0035: │   Request URL: https://registry.yarnpkg.com/@jsr%2fnic-test__test-log
➤ YN0000: └ Completed in 0s 757ms
➤ YN0000: · Failed with errors in 0s 765ms
nicolo-ribaudo commented 5 months ago

yarn add @nic-test/test-log@npm:@jsr/nic-test__test-log@^0.1.0 works if I create this .yarnrc.yml file:

npmScopes:
  jsr:
    npmRegistryServer: "https://npm.jsr.io"

Maybe yarn dlx jsr should create it automatically, rather than .npmrc.

lucacasonato commented 5 months ago

Additional context: this only applies when using >= Yarn 2 (berry), not when using Yarn 1 (classic). Yarn 2 does not read from .npmrc.

@marvinhagemeister Probably we should detect the Yarn version that is in use for a given project, and if it's not Yarn 1, we create the .yarnrc.yml.

Docs: https://yarnpkg.com/migration/guide

Also WHY YARN WHY? :(