Joseph
Joseph•3d ago

Install a local deno package

I want to use a local deno package as a dependency in a second local deno package, and I don't want to include the first package's imports as dependencies of my second package. To spell it out, say I am developing a local package foo located at stuff/foo/deno.json which has a few imports from jsr, npm, etc. Now I have another project stuff/bar/deno.json and the file stuff/bar/main.ts contains import * from "foo". How do I make foo resolve to my local package? If I have "foo": "/full/path/to/stuff/foo/entrypoint.ts" under "imports" in stuff/bar/deno.json, then deno run stuff/bar/entrypoint.ts complains that it can't find all the jsr, npm, etc dependencies of my first project. I've tried hosting foo on GitHub, but this doesn't actually change anything. I've tried bundling foo, but that's a whole different can of worms that produces ridiculous bundle sizes. Surely importing other local deno packages is possible?
5 Replies
Doctor 🤖
Doctor 🤖•3d ago
Try
{
"name": "@a/bar",
"imports": {
"@b/foo": "jsr:@b/foo@0.1.0",
},
"patch": [
"~/Projects/foo/"
]
}
{
"name": "@a/bar",
"imports": {
"@b/foo": "jsr:@b/foo@0.1.0",
},
"patch": [
"~/Projects/foo/"
]
}
Make sure the deno.json of foo has a matching version in your boo's imports. Foo doesn't need to be actually published but the name and version do need to match.
Joseph
JosephOP•2d ago
This would be a perfect work-around, but it seems that the package @b/foo does have to be published on jsr. I'm using deno 2.1.4, maybe this feature is new? (I recieve error: JSR package not found: @b/foo) (Related: https://discord.com/channels/684898665143206084/1320145666478968937)
marvinh.
marvinh.•2d ago
No, the package doesn't need to be published to use the patch feature. The target folder just needs to have a deno.json with the relevant pacakge metadata in it. The package does not need to be published
Doctor 🤖
Doctor 🤖•23h ago
What does the deno.json of @b/foo look like? Can you show both deno.json files?
Joseph
JosephOP•21h ago
My first package, which I want to reuse, has deno.json:
{
"name": "@jollywatt/zettelbuilder",
"version": "1.0.0",
"exports": {
".": "src/mod.ts",
"./server": "src/server.ts",
"./themes/minimal": "src/themes/minimal.tsx",
"./themes/zetteldocs": "src/themes/zetteldocs.tsx"
},
"imports": {
"@deno/gfm": "jsr:@deno/gfm@^0.10.0",
"@preact/preact": "npm:preact@^10.25.4",
"@preact/render": "npm:preact-render-to-string@^6.5.12",
"@std/assert": "jsr:@std/assert@1",
"@std/fs": "jsr:@std/fs@^1.0.8",
"@std/http": "jsr:@std/http@^1.0.12",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/testing": "jsr:@std/testing@^1.0.8",
"@types/react": "npm:@types/react@^19.0.3"
}
}
{
"name": "@jollywatt/zettelbuilder",
"version": "1.0.0",
"exports": {
".": "src/mod.ts",
"./server": "src/server.ts",
"./themes/minimal": "src/themes/minimal.tsx",
"./themes/zetteldocs": "src/themes/zetteldocs.tsx"
},
"imports": {
"@deno/gfm": "jsr:@deno/gfm@^0.10.0",
"@preact/preact": "npm:preact@^10.25.4",
"@preact/render": "npm:preact-render-to-string@^6.5.12",
"@std/assert": "jsr:@std/assert@1",
"@std/fs": "jsr:@std/fs@^1.0.8",
"@std/http": "jsr:@std/http@^1.0.12",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/testing": "jsr:@std/testing@^1.0.8",
"@types/react": "npm:@types/react@^19.0.3"
}
}
(Omitting task , compilerOptions and fmt entries.) The second package, which uses the first package as a dependency, has deno.json:
{
"imports": {
"zettelbuilder": "jsr:@jollywatt/zettelbuilder@1.0.0",
"@std/assert": "jsr:@std/assert@1",
"@deno/gfm": "jsr:@deno/gfm@^0.10.0",
"@std/fs": "jsr:@std/fs@^1.0.8",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/testing": "jsr:@std/testing@^1.0.8",
"@types/react": "npm:@types/react@^19.0.2",
"@preact/preact": "npm:preact@^10.25.3",
"@preact/render": "npm:preact-render-to-string@^6.5.12"
},
"patch": [
"../../zettelbuilder"
]
}
{
"imports": {
"zettelbuilder": "jsr:@jollywatt/zettelbuilder@1.0.0",
"@std/assert": "jsr:@std/assert@1",
"@deno/gfm": "jsr:@deno/gfm@^0.10.0",
"@std/fs": "jsr:@std/fs@^1.0.8",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/testing": "jsr:@std/testing@^1.0.8",
"@types/react": "npm:@types/react@^19.0.2",
"@preact/preact": "npm:preact@^10.25.3",
"@preact/render": "npm:preact-render-to-string@^6.5.12"
},
"patch": [
"../../zettelbuilder"
]
}
The patch url is correct, because it errors clearly if it isn't. Otherwise, deno run in my second package produces error: JSR package not found: @jollywatt/zettelbuilder

Did you find this page helpful?