#Sidecar doesn't run on build, but runs on dev.

30 messages · Page 1 of 1 (latest)

mortal star
#
sudo /Applications/zkVot.app/Contents/MacOS/zkvot-app
stderr:

stderr: #

stderr: # Fatal process OOM in Failed to reserve virtual memory for CodeRange

stderr: #

stderr:

terminated: None

This is the output i got when i run the builded app. This is how my lib.rs looks:

use tauri_plugin_shell::process::CommandEvent;
use tauri_plugin_shell::ShellExt;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
  tauri::Builder::default()
    .plugin(tauri_plugin_shell::init())
    .setup(|app| {
      let sidecar_command = app
        .shell()
        .sidecar("zkvot-desktop")
        .expect("failed to create sidecar");
      let (mut rx, mut _child) = sidecar_command.spawn().expect("failed to spawn sidecar");

      tauri::async_runtime::spawn(async move {
        while let Some(event) = rx.recv().await {
          match event {
            CommandEvent::Stdout(line_bytes) => {
              let line = String::from_utf8_lossy(&line_bytes);
              println!("stdout: {}", line);
            }
            CommandEvent::Stderr(line_bytes) => {
              let line = String::from_utf8_lossy(&line_bytes);
              println!("stderr: {}", line);
            }
            CommandEvent::Error(exit_status) => {
              println!("exit: {}", exit_status);
              break;
            }
            CommandEvent::Terminated(payload) => {
              println!("terminated: {:?}", payload.code);
              break;
            }
            _ => {}
          }
        }
      });

      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

And the sidecar is working well when i run it manually and when run in cargo tauri dev.

mortal star
#

By the way, I'm using https://www.npmjs.com/package/@yao-pkg/pkg to create my sidecar.

#

Just tried with another executable that i created with cpp and it works:

oblique thunder
#

yeah, this is no general problem, but something specific to your app, or at least node (iirc that CodeRange thing is specifically a node or v8 thing)

mortal star
#

My app is also a very very simple hello world app. I think the problem is with the pkg.

#

What if I just make nodejs itself the sidecar? Do you think that would work?

oblique thunder
#

well, if pkg is the issue then possibly, yeah

#

what seems weird is that i didn't find anything similar in the pkg repos (both the original one and the new fork). It's also pretty popular in tauri apps 🤔

mortal star
#

yeah me too, the only similar error i found was this: #general message

#

but couldn't figure out the solution 🤷

#

what is the best way to make nodejs itself a sidecar?

oblique thunder
oblique thunder
oblique thunder
#

I'd love to know what causes this really. We don't do anything to the sidecar so it somehow has to be related to it being in an .app bundle (i assume macos handles app bundles differently than plain binaries somehow).

mortal star
#

should i do it here?

mortal star
#

interestingly, node binary is giving the same error 😮

#

so the problem was not the pkg...

oblique thunder
mortal star
#

the env variables didn't change the behaviour

mortal star
#

okay something very interesting:

  1. node 20 for macos arm sidecat output:
stderr:

stderr: #

stderr: # Fatal process OOM in Failed to reserve virtual memory for CodeRange

stderr: #

stderr:

terminated: None
  1. node 20 for macos intel output first try:
    nothing just hangs

  2. node 20 for macos intel output second try (after cancelling the previous try):
    (attached as txt)

#

my system is macos arm latest btw

mortal star
#

I literally didn't change anything and node binaries started working... My binary that's been made with pkg is still giving the same error. No idea what's going on but i'll just continue with node binaries.

mortal star
#

this code works fine, but when i run the "resources/app.js" still same error... the content of the app.js is only a console log hello world.

mortal star
#
sudo ./src-tauri/target/release/bundle/macos/zkVot.app/Contents/MacOS/node -e 'console.log(123)'

#
# Fatal process OOM in Failed to reserve virtual memory for CodeRange
#

zsh: trace trap  sudo  -e 'console.log(123)'

I tried manually running the binary inside built app.

mortal star
#

Maybe the problem is about the permissions?

oblique thunder
#

If there are OS permissions that somehow control memory allocations, maybe. If you mean Tauri's permissions system, then no.

spring timber
#

Hi, i am currently having same problem with go binary. When my app is build, and i open it with double click, it never starts a sidecar. But it always works in dev mode, and it even works if i start builded app from terminal.
Feels pretty weird.

use tauri_plugin_shell::process::CommandEvent;
use tauri_plugin_shell::ShellExt;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .setup(|app| {
            // Start the sidecar process
            let sidecar_command = app.shell().sidecar("test").unwrap();
            let (mut rx, mut _child) = sidecar_command.spawn().expect("Failed to spawn sidecar");

            tauri::async_runtime::spawn(async move {
                // read events such as stdout
                while let Some(event) = rx.recv().await {
                    if let CommandEvent::Stdout(line_bytes) = event {
                        println!("{}", String::from_utf8_lossy(&line_bytes));
                    }
                }
            });

            Ok(())
        })
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_websocket::init())
        .plugin(tauri_plugin_opener::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}