[Svelte + Vite + Deno 2.0] Svelte and Vite configuration without a package.json
Hello, i am trying to setup a deno 2.0 simple project that has svelte (not svelte kit) and vite on it as well as rely only on a deno.json file for the dependency installation instead of package.json.
My current situation is, i have the project setup with the needed dependencies inside of the deno.json and i have the vite.config.ts, svelte.config.ts and tsconfig.json setup as well. Initially the project works just fine when you run it with just
vite
, but when i try to add a Svelte component like the usual App.svelte i am being hit with this vite error Pre-transform error: Failed to resolve import "svelte/internal/disclose-version" from "src/App.svelte". Does the file exist?
. I am pretty sure that the root cause for this is the fact that the modules with deno 2.0 and deno.json are being installed in a diffrent directory for me on Linux that's .cache/deno
, the file mentioned in the vite error is present in the svelte module folder that is in .cache/deno/npm/registry.npmjs.org/svelte/5.15.0/src/internal/
. I am not sure what i am supposed to do to make vite look into that path to fetch the file it needs. Thanks in advance for any responses4 Replies
do you have a reproduction of this that can be shared?
yes i can give some reproduction steps in a bit
Reproduction steps:
- Create a folder for the project for example
Test Svelte
- Enter Test Svelte
and run deno init
. That will create a deno.json
,main.ts
and main_test.ts
.
- The contents of deno.json
are as follows :
- Create a index.html
in Test Svelte
folder with the following contents :
- Create a svelte.config.ts
in Test Svelte
folder with the following contents :
- Create a tsconfig.json
in Test Svelte
folder with the following contents :
- Create a vite.config.ts
in Test Svelte
folder with the following contents :
- Create a src
folder in Test Svelte
- Create a main.ts
in src
folder with the following contents :
- Create a App.svelte
in src
folder with the following contents :
The directory should look as follows :
TestSvelte
├── deno.json
├── deno.lock
├── index.html
├── src
│ ├── App.svelte
│ └── main.ts
├── svelte.config.ts
├── tsconfig.json
└── vite.config.ts
- Run the project with deno run dev
. When going on the hosted page you will be hit with a Pre-transform error: Failed to resolve import "svelte/internal/disclose-version" from "src/App.svelte". Does the file exist?
Thank you for the repro - i see the same error
is it important for you to use deno.json for config, or would it be fine if I can make it work using the package.json with deno v2 instead? deno has a bit better node compat that way
it is important for me to use deno.json
i am aware it would work with package.json