Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tauri process immediate exit #7731

Closed
birkskyum opened this issue Dec 19, 2023 · 5 comments
Closed

Tauri process immediate exit #7731

birkskyum opened this issue Dec 19, 2023 · 5 comments
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause

Comments

@birkskyum
Copy link
Collaborator

birkskyum commented Dec 19, 2023

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

  • bun --bun x create-tauri-app@latest (selected i.e. typescript / solidjs)
  • cd tauri-app
  • bun --bun run tauri dev

What is the expected behavior?

the expected result can be seen by running bun run tauri dev (without the --bun flag)

bun run tauri dev      
$ tauri dev
     Running BeforeDevCommand (`bun run dev`)
$ vite

  VITE v4.5.1  ready in 212 msLocal:   http://localhost:1420/Network: use --host to expose
        Info Watching /Users/admin/repos/bun-kitchensink/tauri-app/src-tauri for changes...
   Compiling tauri-app v0.0.0 (/Users/admin/repos/bun-kitchensink/tauri-app/src-tauri)
    Finished dev [unoptimized + debuginfo] target(s) in 1.00s
Screenshot 2023-12-19 at 12 14 30

What do you see instead?

bun --bun run tauri dev
$ tauri dev

immediate exit, same for tauri build

Additional information

No response

@birkskyum birkskyum added the bug Something isn't working label Dec 19, 2023
@Electroid Electroid added the needs investigate Needs to be investigated to find the root cause label Dec 19, 2023
@9Morello
Copy link

Reproducible on Ubuntu 22.04 x86-64. The selected JS frameworks don't change the output, as expected.

@9Morello
Copy link

9Morello commented Dec 21, 2023

Okay, so I managed to create a minimal script to reproduce this issue:

// Run this script in a fresh Tauri app folder on a GNU system, created with `bun --bun x create-tauri-app@latest`
// if you're on OSX, replace the nativeBiding with the darwin one from the @tauri-apps folder
let nativeBinding;
try {
  nativeBinding = require("./node_modules/@tauri-apps/cli-linux-x64-gnu/cli.linux-x64-gnu.node");
} catch (e) {
  console.log(e);
}
if (!nativeBinding) {
  throw new Error(`Failed to load native binding`);
}
const { run, logError } = nativeBinding;

const runPromise = async (args, binName) => {
  return new Promise((resolve, reject) => {
    run(args, binName, (res) => {
      if (res instanceof Error) {
        reject(res);
      } else {
        resolve(res);
      }
    });
  });
};

runPromise(["dev"], "bun").catch((err) => {
  logError(err.message);
  console.log(JSON.stringify(err, null, 2));
  process.exit(1);
});

The script above runs as expected using Node 20.5.1, but fails with Bun 1.0.18. Adding a await before the runPromise function makes it work correctly in Bun, and the Tauri window shows up as expected.

I believe the run function is being treated as synchronous when imported by Node.js, but as asynchronous when imported by Bun, thus causing the application to close immediately.

If anyone wants to use Tauri with Bun before this gets fixed, change line 54 of node_modules/@tauri-apps/cli/tauri.js to include an await in the beginning of the line.

Edit: still happening with Bun 1.0.30.

@birkskyum
Copy link
Collaborator Author

I see the same thing on macos. Adding the await will fix bun, but break node with:

➜ npm run tauri dev      

> tauri-node@0.0.0 tauri
> tauri dev

/Users/admin/repos/bun-kitchensink/tauri-app/node_modules/@tauri-apps/cli/tauri.js:54
await cli.run(args, binName).catch((err) => {
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
    at wrapSafe (node:internal/modules/cjs/loader:1281:20)
    at Module._compile (node:internal/modules/cjs/loader:1321:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.13.0

@birkskyum
Copy link
Collaborator Author

birkskyum commented Jun 26, 2024

@9Morello , does it work for you now? My issue/repro is resolved since both of these commands run:

  • bun --bun run tauri dev
  • bun --bun run tauri build

1.1.17+bb66bba1b

@birkskyum
Copy link
Collaborator Author

birkskyum commented Jun 26, 2024

Running the app in the browser yields an error when trying to submit a "Greet" in the app:

@tauri-apps_api_tauri.js?v=2580b4ea:30 Uncaught (in promise) TypeError: window.__TAURI_IPC__ is not a function
    at @tauri-apps_api_taur…js?v=2580b4ea:30:12
    at new Promise (<anonymous>)
    at invoke (@tauri-apps_api_taur…js?v=2580b4ea:21:10)
    at greet (main.ts:9:36)
    at HTMLFormElement.<anonymous> (main.ts:20:5)

But when it opens in it's own window, it'll work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause
Projects
None yet
Development

No branches or pull requests

3 participants