#Can I use the JavaScript API without npm, Yarn etc. just using Cargo?

8 messages · Page 1 of 1 (latest)

prisma nimbus
#

I followed the quick start guide using Cargo because I've never used npm or Yarn before.
First I ran cargo install create-tauri-app --locked, then cargo create-tauri-app.
I entered my project name, selected Rust - (cargo) as frontend language, even though I intend to stick to plain HTML, CSS and JavaScript. And selected Vanilla as UI template.

While trying to use the JavaScript API the application returns an error TypeError: Module name, '@tauri-apps/api/app' does not resolve to a valid URL. The app module is just an example here. The error message can be seen in the screenshot as well. I have included a screenshot of cargo tauri info.

Would be nice if someone could enlighten me on what I am doing wrong or do not understand.
Thanks in advance.

light merlin
#

you can't use the package but you can use the global api.
Just enable withGlobalTauri in tauri.conf.json and then you can do stuff like window.__TAURI___.tauri.invoke

prisma nimbus
#

Could you please elaborate on that?

light merlin
#

Or what do you want to know?

prisma nimbus
#

Sorry, I was unclear. withGlobalTauri in tauri.conf.json is true in my case, but I don't know how to use the global API. I also have no JavaScript experience.

light merlin
#

ah alright. So in general all the example still apply but you'll have to change the imports a bit. Using your example you would replace this: ts import { getVersion } from "@tauri-apps/api/app"; with ```ts
const { getVersion } = window.TAURI.app;

#

alternatively you can skip the import and do something like ```ts
const version = await window.TAURI.app.getVersion();