Using JSR with Bun #11897
jordanbtucker
started this conversation in
General
Using JSR with Bun
#11897
Replies: 1 comment 1 reply
-
❯ bunx jsr add @ryoppippi/unplugin-typia |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The JavaScript Registry (JSR) is a modern package registry for JavaScript and TypeScript. JSR works with many runtimes (Node.js, Deno, browsers, and more) and is backwards compatible with npm.
You can also use it with Bun.
Let's say you want to use
@std/encoding
from the Deno Standard Library hosted on JSR.Run the following command in your project directory:
Now you can use imports like this, complete with typings and documentation.
For the nitty gritty details, this works because
jsr
adds a scoped registry tobunfig.toml
, and adds an alias to a scoped package as a dependency inpackage.json
that looks like this:The following command is equivalent to running
bunx jsr add --bun @std/encoding@^0.224.3
:Note: The
--bun
argument is only required if you do not yet have abun.lockb
file or if any other package manager's lock files exist (package-lock.json
,pnpm-lock.yaml
,yarn.lock
, etc.). In other words, runningjsr add
is equivalent to runningjsr add --bun
if abun.lockb
file exists and no other lock files exist.Note:
bun add
currently doesn't resolve version numbers when using aliases likenpm
does. For example, runningbun add @std/encoding@npm:@jsr/std__encoding
will result in"@std/encoding": "npm:@jsr/std__encoding"
being added as a dependency, while runningnpm install @std/encoding@npm:@jsr/std__encoding
will add"@std/encoding": "npm:@jsr/std__encoding@^0.224.3"
(note the version automatically being resolved). For this reason,jsr add --bun
will not resolve version numbers either, so it's recommended to add the version or range manually.Beta Was this translation helpful? Give feedback.
All reactions