Siki
Siki3mo ago

Deno workspace with sveltekit(package.json) import native deno library dependency

I need information & help with the following: - I am using Deno workspace with sveltekit(package.json) - ./client and deno library ./services (deno.json) - Is it possible to import services in client? - If yes how?
4 Replies
marvinh.
marvinh.3mo ago
If you add the official deno-vite-plugin to your vite configuration in vite.config.ts it should work. https://github.com/denoland/deno-vite-plugin
Siki
SikiOP3mo ago
Just by installing and setting up deno vite plugin,
- how do I add services to package.json - can I get an example?
rykuno
rykuno3mo ago
also having this issue.
Giraffe
Giraffe2mo ago
In my case, I am planning to build a deno project library into an npm package, as it is an npmjs package already — and wanted to use deno. For the building process I use dnt. (Deno 2.0.6) - ./app sveltekit with package.json (testing suite) - ./library my library I've tried combinations of ./deno.jsonc
{
"workspace": [
"app",
"sveltekit-zero-api"
]
}
{
"workspace": [
"app",
"sveltekit-zero-api"
]
}
and ./package.json
{
"workspaces": [
"app",
"sveltekit-zero-api"
]
}
{
"workspaces": [
"app",
"sveltekit-zero-api"
]
}
⸻⸻⸻⸻⸻⸻ This setup means I have a ./library/package.json with some exports:
{
"name": "library",
"exports": {
".": "./src/index.ts",
"./server": "./src/server/index.ts"
},
"etc": "..."
}
{
"name": "library",
"exports": {
".": "./src/index.ts",
"./server": "./src/server/index.ts"
},
"etc": "..."
}
What I've tried with ./app/deno.jsonc is doing
{
"imports": {
"library": "../library"
}
}
{
"imports": {
"library": "../library"
}
}
after adding the deno-vite-plugin per your suggestion. I've tried the "npm"-way which is ./app/package.json
{
"devDependencies": {
"library": "*"
}
}
{
"devDependencies": {
"library": "*"
}
}
But that just installs the npm package with that name. I've tried the "bun"-way which is ./app/package.json
{
"devDependencies": {
"library": "workspace:*"
}
}
{
"devDependencies": {
"library": "workspace:*"
}
}
but here, workspace isn't recognized. Workaround What have worked, is doing deno install --allow-scripts, then using the beforementioned "bun"-way, and then doing bun install When I run the project, it works as expected. @marvinh. I presume this is not supported yet? *Related discussions on Github 26138 26721 I see it has already been assigned. Waiting patiently🤞🏿 Btw what I ended up doing was converting the sveltekit app to a ./app/deno.jsonc file. In the ./app/package.json, I use the Bun-syntax. When installing the monorepo, I remove the Bun-syntax from the ./app/package.json, do deno install --allow-scripts and re-add it, and do bun install (Bun will just "apply" the workspace dependency, as there are no other packages)
{
"name": "app",
"version": "0.0.1",
"type": "module",
"devDependencies": {
"library": "workspace:*"
}
}
{
"name": "@scope/app",
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.0",
"@sveltejs/adapter-auto": "npm:@sveltejs/adapter-auto@^3.0.0",
"@sveltejs/kit": "npm:@sveltejs/kit@^2.0.0",
"etc": "..."
{
"name": "app",
"version": "0.0.1",
"type": "module",
"devDependencies": {
"library": "workspace:*"
}
}
{
"name": "@scope/app",
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.0",
"@sveltejs/adapter-auto": "npm:@sveltejs/adapter-auto@^3.0.0",
"@sveltejs/kit": "npm:@sveltejs/kit@^2.0.0",
"etc": "..."
This is good enough for me right now. But definitely an annoyance I hope see fixed🤞🏿
Sidenote since others also use SvelteKit. I had to do { compilerOptions: { runes: true } } in svelte.config.js, as my site was throwing an error when attempting to use svelte legacy. This only happened with the Deno install — so it might be a compatability issue.

Did you find this page helpful?