I have a Tauri app sidecar written in Node.js, I use pkg
to package the node app into an executable, the name of the sidecar is server-x86_64-pc-windows-msvc.exe
.
I am able to use @tauri-apps/api/shell
in the client side and execute the sidecar:
import { Command } from '@tauri-apps/api/shell';
const command = Command.sidecar('bin/server');
console.log(command)
command.on('close', data => {
console.log(`command finished with code ${data.code} and signal ${data.signal}`)
});
const output = await command.execute();
console.log("???? ~ output:", output)
However, one of the packages I am using inside the node app (the sidecar) requires 3rd party executable and files, so when I am executing the command
I am facing a node.js Error: Cannot find module 'C:snapshotdist/build/Release...
error.
When I am executing server-x86_64-pc-windows-msvc.exe
directly on my PC it works fine and there is no problem with requiring the 3rd party files.
tauri.conf.json:
{
"$schema": "../../../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "yarn build:browser",
"beforeDevCommand": "yarn dev:browser",
"devPath": "http://localhost:4000",
"distDir": "../dist"
},
"package": {
"productName": "desktop-app",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"execute": true,
"sidecar": true,
"scope": [{ "name": "bin/server", "sidecar": true }] // this is important
}
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": ["bin/server"], // this is important
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/[email protected]",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "Desktop Server",
"width": 800
}
]
}
}
Folder structure:
desktop-app/
├─src/
│ ├─index.html
│ ├─index.js
│ └─...
└─src-tauri/
├─bin/
│ ├─build/
│ │ └─Releases/
│ │ ├─3rd-party-executable
│ │ ├─3rd-party-file
│ │ └─...
│ └─server-x86_64-pc-windows-msvc.exe
├─src/
├─target/
├─tauri.conf.json
└─...