#Cannot import { emit, listen } event
17 messages · Page 1 of 1 (latest)
You don't have a bundler.
Require is suppose to work still no?
No, that's not valid ECMAScript.
It's not required. See the top of each Tauri JS API page for details about how to use the API without a bundler. https://tauri.app/v1/api/js/event
If you're starting from scratch, I recommend using TypeScript because it will save you hours of console.debugging.
the browser understands esm just fine, I don't see why you'd need typescript for this 🤔
@tauri-apps/api/event isn't ESM. It's a Node.js library.
these are orthogonal, you mean that it uses nodejs API? I don't think that's right, if anything the issue is the other way around
If you're not using Node.js, one option is to enable withGlobalTauri and reference it as const { emit, listen } = window.__TAURI__.event; which is the instructions on the website as I mentioned earlier. The other option is to manually copy the ESM files from the Node.js library which makes far less sense since you still have to install Node.js to get the files and then copy or symlink the files into your src folder.
I did say that TypeScript is not required. It has never been a requirement for developing with Tauri. I recommend TypeScript because it will tell you about type errors and provides offline documentation. Without TypeScript, you're constantly visiting https://tauri.app/v1/api/js or reading the Rust source code to find out the types that the API accepts and returns.
I don't recommend it for large existing projects as the benefits do not scale with the work it takes to migrate and add proper references to each file if your code is split into multiple files that made assumptions about the previous file being loaded (this was a very common practice before ESM).