Kokomi
Kokomi4mo ago

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
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"]
}
{
"workspace": ["./frontend", "./backend"]
}
backend/main.ts
export function sayHi() {
console.log("Hi");
}
export function sayHi() {
console.log("Hi");
}
backend/deno.json
{
name: "@scope/backend",
version: "0.0.1"
}
{
name: "@scope/backend",
version: "0.0.1"
}
frontend/src/routes/+page.svelte
<script lang="ts">
import { sayHi } from "@scope/backend";
</script>
<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.
'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
import { sayHi } from "@scope/backend"; // This imports correctly
How can I correctly import modules within .svelte files?
1 Reply
Kokomi
KokomiOP4mo ago
I realized after sending this that SvelteKit projects inherently depend on Node.js, so it might not be possible to resolve this issue purely with Deno. I acknowledge that I might not fully understand the intricacies of how these tools interact in this context.