KokomiK
Deno17mo ago
1 reply
Kokomi

Deno Workspace Not Functioning in .svelte Files

Description


I am using Deno's monorepo feature to share modules between the backend and frontend of my project. I’ve set up the following directory structure (omitting some files for brevity):

project/
├─ frontend/
│  ├─ deno.json
│  ├─ src/
│  │  ├─ routes/
│  │  │  ├─ +page.svelte
│  │  │  ├─ sample.ts
│  ├─ package.json
├─ backend/
│  ├─ main.ts
│  ├─ deno.json
├─ deno.json


The files are as follows (details simplified for clarity, as they are not the main issue):

project/deno.json
{
  "workspace": ["./frontend", "./backend"]
}


backend/main.ts
export function sayHi() {
  console.log("Hi");
}


backend/deno.json
{
  name: "@scope/backend",
  version: "0.0.1"
}


frontend/src/routes/+page.svelte
<script lang="ts">
import { sayHi } from "@scope/backend";
</script>


However, when importing in the +page.svelte file, I encounter an issue, and the following error messages are displayed:

'sayHi' is declared but its value is never read.
Cannot find module '@scope/backend' or its corresponding type declarations.


Interestingly, when I create a sample.ts file in the same directory, the module is imported without any issues:

frontend/src/routes/sample.ts
import { sayHi } from "@scope/backend"; // This imports correctly


How can I correctly import modules within .svelte files?
Was this page helpful?