tauri: [bug] window.__TAURI_IPC__ is not a function
Describe the bug
I followed the documentation to create my first app using: yarn create tauri-app
I receive an error when trying to run a basic echo command.
Thank you.
Reproduction
yarn create tauri-app- Choose Svelte w/ Typescript
cd <app_name>yarn installyarn tauri dev- Add the following as code inside the script/main tags:
<script lang="ts">
import { Command } from '@tauri-apps/api/shell';
export let name: string;
const command = new Command('echo', 'message').execute();
</script>
<main>
<h1>Hello {name}!</h1>
{#await command}
<p>waiting...</p>
{:then output}
<p>output: {output}</p>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</main>
- Notice the error printed to the page:
window.__TAURI_IPC__ is not a function - Check the window in the console (it doesn’t exist)
Expected behavior
'message' is returned
Platform and versions
> monocole@1.0.0 tauri
> tauri "info"
Operating System - EndeavourOS, version Rolling Release X64
Node.js environment
Node.js - 17.5.0
@tauri-apps/cli - 1.0.0-rc.2
@tauri-apps/api - 1.0.0-rc.0
Global packages
npm - 8.4.1
pnpm - Not installed
yarn - 1.22.17
Rust environment
rustc - 1.58.1
cargo - 1.58.0
Rust environment
rustup - 1.24.3
rustc - 1.58.1
cargo - 1.58.0
toolchain - stable-x86_64-unknown-linux-gnu
App directory structure
/public
/src
/.vscode
/node_modules
/src-tauri
App
tauri.rs - 1.0.0-rc.1
build-type - bundle
CSP - default-src 'self'
distDir - ../public
devPath - http://localhost:8080/
framework - Svelte
bundler - Rollup
Stack trace
None
Additional context
Firefox 97.0 (64-bit)
Kernel:
uname -r
> 5.15.21-hardened1-1-hardened
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (11 by maintainers)
Wait a second, I think this is a misunderstanding on my part.
After creating the project and following the instructions to run it, I ran into the error.
The issue is that I was starting the project with
yarn run dev. I checkedpackage.jsonand saw there is atauriscript, and when run, it outputs there is adevsub-command. Runningnpm run tauri devbuilds and runs the app in a window (rather than the browser), andTAURIexists on the window now.I see a new error:
program not allowed on the configured shell scope: echo; however, I suspect that is corrected in thetauri.conf.json, so I’ll follow the docs from here.Thank you for your time!
Me too. I followed a fresh Tauri installation on my Mac, specifying Vue and Typescript frontend
npm create tauri-app@latest, installed the npm packages, then rannpm run tauri devand got the web page appearing ok.But clicking
Greetgives me the same error.Why would the recommended default app be broken - for over a year now? Am I missing something?
P.S. Then building the app with the recommended
npm run tauri buildgives meNot a good introductory experience. I must have missed something in the installation? I installed cargo and ran all the npm commands and created the default project.
Yeah, the tauri scripts are only injected into tauri windows 😃
Just stumbled across this while using create tauri-app as I ran
pnpm devinstead ofpnpm tauri dev. I started to think the Greet functionality in the scaffolded app was broken.I agree that a console error would be valuable, as this was the first place I looked to see what was happening.
I also think it is worth swapping
pnpm devto run tauri by default and change the vite web dev topnpm vite devas the fundamental purpose of this is to build a tauri app. I am seeing the same pattern with most of the tauri templates under awesome-tauri.I am just saying it is an option to have web/tauri-app project from single codebase but the template is tailored towards tauri (with the possiblity for future hybrid project). In addition to that, we still need
yarn devto exist soyarn tauri devcould run it before opening the tauri app.It does, the CLI prints
What kind of a fallback do you have in mind? because tauri IPC can’t work in a browser at all, it has to be a tauri window.
I think we could maybe try to detect that tauri APIs are loaded on a browser and maybe
console.errthat tauri APIs doesn’t work in a normal browser and you may have missed a tauri specific guard or just used the wrong npm script.I’ve fallen into it as well. As i run
yarn devwhich startsvitein web browser. I’ve usedyarn create tauri-app.After updating to
@tauri-apps/api@2.0.0-beta.3the import fails:import {invoke} from '@tauri-apps/api'I had to change it to:
import {invoke} from "@tauri-apps/api/core"then it worked.
@bennekrouf Try updating your
@tauri-apps/apipackage (in package.json) to 2.0.0-beta.0.We’re not aware of any issues with the templates as long as you use the tauri window. Again, opening the frontend in your default browser is not supported.
If you encounter any issues, please post the following things:
npm run tauri info(swap npm with the package manager you’re using)This is not a good look for Tauri, since it’s literally supposed to be install, run and play.
This bug still happens with a fresh Tauri installation. (Windows 10, React javascript boilerplate chosen)