How to use Javascript Registry with Bun?

53 Views Asked by At

I'm trying to install an NPM package via the new JSR package registry with the following command:

bunx jsr add -D @jsr/total-typescript__ts-reset

The command did generate a bunfig.toml, but did not install my dependency nor update my package.json file like it's supposed to.

Here is the bunfig.toml that it created:

[install.scopes]
"@jsr" = "https://npm.jsr.io"

And here is the error it throws:

Setting up bunfig.toml...ok
Installing @total-typescript/ts-reset...
$ bun add --dev @total-typescript/ts-reset@npm:@jsr/total-typescript__ts-reset
bun add v1.0.35 (940448d6)
   @jsr/total-typescript__ts-reset [1/1]
error: package "@jsr/total-typescript__ts-reset" not found npm.jsr.io/@jsr%2ftotal-typescript__ts-reset 404
error: @total-typescript/ts-reset@npm:@jsr/total-typescript__ts-reset failed to resolve
Child process exited with: 1

Isn't JSR supposed to resolve to NPM if it can't find the package in the registry? Am I just executing the command incorrectly?

Thank you!

1

There are 1 best solutions below

0
Gin Quin On

You mixed two possible syntaxes.

The command you want to run is:

bunx jsr add -D @total-typescript/ts-reset


The other alternative is to declare how to use the jsr registry. In that case you first have to create an .npmrc file, and add the following lines to it:

@jsr:registry=https://npm.jsr.io

Then, you can install with bun add:

bun add -D @jsr/total-typescript__ts-reset

(Notice how the package name is different.)