Local Deno package imports: Use package's deno.json config "exports" map?
I'm working in a Deno workspace where the outer workspace
deno.json
references a project within (at some sub-dir path).
- The project's deno.json
uses the "exports" option to map "."
to "./src/mod.ts"
.
- The workspace root's deno.json
then references this directory in the "imports"
map, from "package-a"
to "./package-a"
.
I would infer/expect (incorrectly?) based on Deno + JSR's import docs, that the outer workspace's import would use the values found in project-a's "exports" map. Running the project returns the following error:
Is my assumption incorrect? Is there something else wrong with my setup?
Ultimately, what I'd like is to respect the package's "exports"
values, such that 1) I can import with a short specifier, and 2) I can reference either a local directory or the package on JSR without changing any import code.8 Replies
Note: I'm seeing that I might be able to just reference a singular export path and then reference that file directly in the imports, but I'd prefer to keep my existing exports structure (if possible). I also wonder about other unintended side-effects related to bypassing the package level configs.
@dsherret can you advise here?
deno.json - Maps import "project-a" to "./project-a"That will map it to the directory, which isn't supported. If you give project-a a name like
@some-scope/project-a
in the deno.json then you should be able to just import it with that bare specifier anywhere in the workspaceif you ignore the squiggles on project-a, this works

Perfect, thank you so much!
Seems this works great for projects within the same workspace.
An aside: I have a similar use-case, importing packages from a local directory which is adjacent to the root workspace; i.e., two workspaces next to each other, where
workspace-a
imports workspace-b
.
As local directory imports aren't supported, I'm just referencing the necessary modules directly in the workspace-a
import map. Is this the recommended way to do things?if you have a workspaces outside another workspace you can probably use the
"patch"
feature (soon to be renamed "link"
I think) https://github.com/denoland/deno/issues/25110GitHub
Tracking: stabilization of "patch" feature · Issue #25110 · denol...
// deno.json { "patch": [ "../some-package-or-workspace" ] } #25068 Questions: Is "patch" an ok name? Isn't it confusing with the idea of "patching a package&...
that will link in the specified package or workspace's packages in the current workspace