wRadion
wRadion•this hour

Import local package in sub folder workspace

Hello! I'm trying to understand how the workspace/local imports work. I've managed to follow along with the simple add/substract example from the docs. But I have another folder structure than this in my project. Imagine something as follows:
root
|- add
|- deno.json // @scope/add
|- index.ts
|- substract
|- deno.json // @scope/substract
|- index.ts
|- maths
|- geometry
|- deno.json
|- index.ts // doesn't find @scope/add or @scope/substract
|- deno.json // workspace: ["./geometry"]
|- deno.js // workspace: ["./add", "./substract", "./maths"]
root
|- add
|- deno.json // @scope/add
|- index.ts
|- substract
|- deno.json // @scope/substract
|- index.ts
|- maths
|- geometry
|- deno.json
|- index.ts // doesn't find @scope/add or @scope/substract
|- deno.json // workspace: ["./geometry"]
|- deno.js // workspace: ["./add", "./substract", "./maths"]
Now if I wanna import add or substract inside my geometry module, it doesn't find it. But if I move everything one workspace up (move geometry directly in the root workspace) then it works. I just have might the whole workspace/module thing wrong, so I would like to know how it works and what's the best way to fix this. Thanks!
1 Reply
wRadion
wRadionOP•this hour
Okay I've managed to fix my issue (that was quick lol). Writing it actually helped me understand that maybe the @scope thing is named scope, because it represents the workspace scope (I'm dumb 😅 ). So the idea is simply to declare the submodule in the root workspace:
root
|- add
|- deno.json // @scope/add
|- index.ts
|- substract
|- deno.json // @scope/substract
|- index.ts
|- maths
|- geometry
|- deno.json
|- index.ts // finds @scope/add or @scope/substract
|- deno.json // workspace: ["./add", "./substract", "./maths/geometry"]
root
|- add
|- deno.json // @scope/add
|- index.ts
|- substract
|- deno.json // @scope/substract
|- index.ts
|- maths
|- geometry
|- deno.json
|- index.ts // finds @scope/add or @scope/substract
|- deno.json // workspace: ["./add", "./substract", "./maths/geometry"]

Did you find this page helpful?