Support Tauri
Platform
Darwin 23.0.0 arm64 arm
Version
deno 1.37.1
Repro
-
deno run -A npm:create-tauri-app- Select i.e. Typescript, Solid
-
deno run -A npm:tauri dev
Expected
I.e. npx tauri dev gives:
➜ npx tauri dev
Running BeforeDevCommand (`npm run dev`)
> [email protected] dev
> vite
VITE v4.4.9 ready in 227 ms
➜ Local: http://localhost:1420/
➜ Network: use --host to expose
Info Watching /Users/admin/repos/tauri-test/create-tauri-app/src-tauri for changes...
Compiling create-tauri-app v0.0.0 (/Users/admin/repos/tauri-test/create-tauri-app/src-tauri)
Finished dev [unoptimized + debuginfo] target(s) in 0.68s
Actual
➜ deno run -A npm:tauri dev
error: package 'tauri' did not have a bin property in its package.json
Any update?
I'm in a Tauri setup with a SvelteKit frontend. Deno is panicking with this backtrace.
============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.
Platform: linux x86_64
Version: 1.43.6
Args: ["/home/aman/.deno/bin/deno", "run", "-A", "npm:[email protected]", "dev"]
thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/notify-5.0.0/src/inotify.rs:596:32:
called `Result::unwrap()` on an `Err` value: "SendError(..)"
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: core::result::unwrap_failed
3: <notify::inotify::INotifyWatcher as notify::Watcher>::watch
4: deno_runtime::ops::fs_events::op_fs_events_open::op_fs_events_open::v8_fn_ptr
5: Builtins_CallApiCallbackOptimizedNoProfiling
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Deno v1.43.6 Rustc v1.78.0 Tauri v1.6.6 Vite v5.2.11
I upgraded to Deno 1.44 to assess if it was feasible for me to use deno for tauri now, because this is one of the tickets relying on binaries and hoped this would help:
- https://github.com/denoland/deno/pull/23496
this is what I get
➜ DENO_FUTURE=1 deno install npm:tauri
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
Add tauri - npm:tauri@^0.15.0
error: Can't set up 'vite' bin at ../.deno/[email protected]/node_modules/vite/bin/vite.js
Caused by:
File exists (os error 17)
and
➜ DENO_FUTURE=1 deno run npm:tauri dev
error: '/Users/admin/repos/deno-kitchensink/create-tauri-app/node_modules/.deno/[email protected]/node_modules/tauri/package.json' did not have a bin property
With the binary install resolved, this seems to mainly be a matter of confusion/mess with the DENO_FUTURE=1 and the npm:tauri. For instance, the package scripts has an entry called "tauri": "tauri", and it doesn't work well with DENO_FUTURE=1 deno task tauri dev, and DENO_FUTURE=1 deno run npm:tauri.
For Deno 2 rc.2 + Tauri 1, things run as expected, except the "Greet" button in the demo, it'll give this console error:
@tauri-apps_api_tauri.js?v=152d049d:30 Uncaught (in promise) TypeError: window.__TAURI_IPC__ is not a function
at @tauri-apps_api_tauri.js?v=152d049d:30:12
at new Promise (<anonymous>)
at invoke (@tauri-apps_api_tauri.js?v=152d049d:21:10)
at greet (main.ts:9:36)
at HTMLFormElement.<anonymous> (main.ts:20:5)
Trying Tauri 2 rc
- #25649
With deno2 rc + tauri2 rc:
Note: For creation npm is needed, because of cli issues passing --rc flag to deno run:
- #25904
npm create tauri-app@latest -- --rc
deno install
deno task dev
Error in console
@tauri-apps_api_core.js?v=1934d98c:89 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'invoke')
at invoke (@tauri-apps_api_core.js?v=1934d98c:89:37)
at greet (App.tsx:12:23)
at HTMLFormElement.<anonymous> (App.tsx:37:11)
Does it work now? Sounds like tauri apps is not deno compatible from the error message. The rust bindings is probably specific to node.
What are the benefits of using deno for this? Can I still use pnpm as the package manager?
Does it work now? Sounds like tauri apps is not deno compatible from the error message. The rust bindings is probably specific to node.
I use it just fine. There are no Rust bindings in Tauri (apart from the CLI), it is all IPC.
What are the benefits of using deno for this? Can I still use pnpm as the package manager?
You can see the benefits of Deno on its website. You shouldn't use pnpm with Deno.
@ninjadev64 how is it working for u?
I use it just fine.
For me deno task dev still doesn't work, and failing because of the tauri cli/bin script
The only way I see to make deno work with tauri is to write custom dev script to run tauri cli or start the vite dev server using a custom deno script.
I've never tried building the app yet, so not sure if above custom script will be sufficient to make things work with Tauri builds.
In my package.json I have the normal vite dev, build and preview scripts. In my tauri.conf.json I have the beforeDevCommand or whatever it is as deno task dev. Then cargo tauri dev and it works.
Thanks for sharing.
I think it should work with cargo tauri dev with the changes u described above, but I am not able to run cargo tauri dev on my linux machine. It keeps on throwing no such command: tauri error
~~I couldn't find any details in the documentation either~~
No worries, I found a solution somewhere in the tauri issues. We first need to install tauri-cli, i.e. run cargo install tauri-cli to run the tauri cli commands using cargo.
Following steps works for me:
cargo install create-tauri-app tauri-cli --locked
cargo create-tauri-app foo
cd foo
deno install
# Ensure u update tauri.conf.json to use deno commands, i.e.
# change to the following:
# "beforeDevCommand": "deno task dev",
# "beforeBuildCommand": "deno task build",
# and then run the following command
cargo tauri dev # from repo's root directory.
I believe this issue can be closed.
@ninjadev64 , when I made this ticket, it was all Tauri 1 + Deno 1. Now both Tauri and Deno are stable in v2, and I think there is still a few tweaks needed, but let's focus on ensuring that this forward-looking combination works.
I gave Tauri 2 + Deno 2 a try:
There's a deno template when running create-tauri-app, which contains a valid tauri.conf.json. The artifacts are bundled with vite, which is invoked by deno task.
Linting does not seem to work out of the box despite there's tsconfig.json in the project root. You'll have to manually create a deno.jsonc which replicates the compilerOptions.lib specified:
{
"compilerOptions": {
"lib": [
"ES2021",
"DOM",
"DOM.Iterable"
]
}
}
Deno specific features won't work. For example
// https://docs.deno.com/runtime/fundamentals/node/#using-npm-packages
import * as emoji from "npm:node-emoji";
console.log(emoji.emojify(`:sauropod: :heart: npm`));
will result in an error.
~~deno does not play that well with tauri currently. In all of the js examples vite is used, and vite uses it's own esbuild.~~
Edit: turns out what is needed is simply
deno install npm:@deno/vite-plugin
So to make the tauri template fell more like a deno 2 project:
cd tauri-app
rm package.json tsconfig.json
touch deno.jsonc
deno.jsonc:
{
"nodeModulesDir": "auto",
"tasks": {
"dev": "deno run -A npm:vite",
"build": "deno check src/main.ts && deno run -A npm:vite build",
"preview": "deno run -A npm:vite preview",
"tauri": "deno run -A npm:@tauri-apps/cli"
},
"compilerOptions": {
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
]
},
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.0",
"vite": "npm:vite@^5.3",
"@tauri-apps/api": "npm:@tauri-apps/api@^2",
"@tauri-apps/plugin-shell": "npm:@tauri-apps/plugin-shell@^2",
"@tauri-apps/cli": "npm:@tauri-apps/cli@^2"
}
}
In vite.config.ts, add:
import deno from '@deno/vite-plugin';
// ...
export default defineConfig(async () => ({
// ...
plugins: [deno()],
}));
Finally:
deno install
deno task tauri dev
🥳
@xiaoas , awesome, sounds like the deno template just need a few tweaks!
I was also able to get it working. Here is my example repository.
https://github.com/raine-works/tauri-deno/tree/master
Im new to all of this so i wanna ask, by implementing this you essentially are replacing rust with deno for backend?
Im new to all of this so i wanna ask, by implementing this you essentially are replacing rust with deno for backend?
Tauri does not include nodejs as backend or any js backend. If you need backend service need to use with sidecar.
there is attempt to run deno with tauri without nodejs. but this tauri-cc project is bridging tauri and deno by ipc connection. so deno cores needs to be modified. https://github.com/Cassielxd/tauri-cc
other solution is available, run deno compiled js backend as tauri sidecar. i have made working example, here. https://github.com/bignikescar/tauri-deno-solidjs/tree/solid-start-deno-tauri