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

Vite error when using bun with Tauri #3237

Closed
MidKnightXI opened this issue Jun 7, 2023 · 13 comments
Closed

Vite error when using bun with Tauri #3237

MidKnightXI opened this issue Jun 7, 2023 · 13 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@MidKnightXI
Copy link

What version of Bun is running?

0.6.7

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

  • Create a new Tauri project
  • Replace the dependencies with yarn in tauri.conf.json
  • Install the node_modules with bun install
  • Run bun run tauri dev

What is the expected behavior?

Vite should create a server for the front and tauri should build the project with cargo

What do you see instead?

$ tauri dev
     Running BeforeDevCommand (`bun run dev`)
$ vite
failed to load config from /Users/vite.config.js
error when starting dev server:
Error: The service was stopped: spawn /Users/node_modules/esbuild-darwin-arm64/bin/esbuild EACCES
    at /Users/node_modules/esbuild/lib/main.js:1122:25
    at Object.responseCallbacks.<computed> (/Users/node_modules/esbuild/lib/main.js:680:9)
    at ChildProcess.afterClose (/Users/node_modules/esbuild/lib/main.js:670:28)
    at ChildProcess.emit (node:events:390:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
error: script "dev" exited with code 1 (SIGHUP)
       Error The "beforeDevCommand" terminated with a non-zero status code.
error: script "tauri" exited with code 1 (SIGHUP)

Additional information

// package.json

{
  "name": "",
  "version": "",
  "description": "",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview",
    "tauri": "tauri"
  },
  "license": "MIT",
  "devDependencies": {
    "@tauri-apps/cli": "^1.3.1",
    "vite": "^3.0.0",
    "vite-plugin-solid": "^2.3.0"
  },
  "dependencies": {
    "@tauri-apps/api": "^1.1.0",
    "solid-js": "^1.4.7"
  }
}
// vite.config.js
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

export default defineConfig({
  plugins: [solidPlugin()],

  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  // prevent vite from obscuring rust errors
  clearScreen: false,
  // tauri expects a fixed port, fail if that port is not available
  server: {
    port: 1420,
    strictPort: true,
  },
  // to make use of `TAURI_DEBUG` and other env variables
  // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
  envPrefix: ["VITE_", "TAURI_"],
  build: {
    // Tauri supports es2021
    target: ["es2021", "chrome100", "safari13"],
    // don't minify for debug builds
    minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
    // produce sourcemaps for debug builds
    sourcemap: !!process.env.TAURI_DEBUG,
  },
});
// tauri.conf.json "build" variable

{
  "build": {
    "beforeDevCommand": "bun run dev",
    "beforeBuildCommand": "bun run build",
    "devPath": "http://localhost:1420",
    "distDir": "../dist",
    "withGlobalTauri": false
  },
}
@MidKnightXI MidKnightXI added the bug Something isn't working label Jun 7, 2023
@Electroid Electroid added the node.js Compatibility with Node.js APIs label Jun 7, 2023
@paperclover
Copy link
Member

this is a duplicate of #3216

but the EACCES on spawn esbuild is a little concerning.

can you try this again not within /Users but instead in a folder like /Users/yournamehere/example, might be a permission error.

@MidKnightXI
Copy link
Author

It wasn't in my /Users but on my personal user directory, I also tried with sudo but same error

@birkskyum
Copy link
Collaborator

birkskyum commented Jul 25, 2023

@MidKnightXI , the failed to load config from /Users/vite.config.js is likely to be resolved by some recent changes (#3724, #3783, #3732) in the latest canary bun upgrade --canary. Would you mind checking if this error still persist?

@birkskyum
Copy link
Collaborator

birkskyum commented Jul 25, 2023

I find that even running the tauri creation script gives a Strict mode error:

  • bun --bun x create-tauri-app@latest

Output:

➜ bun --bun x create-tauri-app@latest


error: Declarations with the name arguments cannot be used with esm due to strict mode

const [bin, script, ...arguments] = process.argv;
                       ^
/private/tmp/create-tauri-app@latest--bunx/node_modules/create-tauri-app/create-tauri-app.js:10:24 249
error: "create-tauri-app" exited with code 1 (SIGHUP)

@MidKnightXI
Copy link
Author

@MidKnightXI , the failed to load config from /Users/vite.config.js is likely to be resolved by some recent changes (#3724, #3783, #3732) in the latest canary bun upgrade --canary. Would you mind checking if this error still persist?

I'll check tonight if I can, will post the result when I'm done trying 👍🏻

@MidKnightXI
Copy link
Author

~ bun --bun x create-tauri-app@latest


error: Declarations with the name arguments cannot be used with esm due to strict mode

const [bin, script, ...arguments] = process.argv;
                       ^
/Users/midknight/.config/yarn/global/node_modules/create-tauri-app/create-tauri-app.js:10:24 249
error: "create-tauri-app" exited with code 1 (SIGHUP)

@paperclover
Copy link
Member

paperclover commented Aug 15, 2023

that is not related. the error shown is related to strict mode. if you rename the variable, things almost work but there is an event loop related bug which can be fixed by using top-level await on their .run() function later in the same file. this brings it to working but with stability issues.

@birkskyum
Copy link
Collaborator

This issue with arguments and strict mode is now fixed upstream in create-tauri-app Node.js CLI, but it's not released yet.

@s9kt
Copy link

s9kt commented Sep 25, 2023

This doesn't seem to be entirely fixed (at least for me). While I'm able to create the Tauri app, I can't run it with bun --bun run tauri dev.

$ tauri dev

error: Declarations with the name arguments cannot be used with esm due to strict mode

const [bin, script, ...arguments] = process.argv
                       ^
/home/dev/tauri-app/node_modules/@tauri-apps/cli/tauri.js:10:24 246
error: script "tauri" exited with code 1 (SIGHUP)

bun run tauri dev compiles and works as intended though.

@birkskyum
Copy link
Collaborator

birkskyum commented Sep 29, 2023

@s9kt , as explained here will the error be resolved when a new version of @tauri-apps/cli comes out.

@birkskyum
Copy link
Collaborator

birkskyum commented Dec 19, 2023

bun --bun x create-tauri-app@latest works now to create a new repo.

When running the bun --bun run tauri dev or tauri build, the cli exists immediately

@birkskyum
Copy link
Collaborator

birkskyum commented Dec 19, 2023

continuation of this

@AlbertMarashi
Copy link

Anyone still getting this issue?

vitejs/vite#17851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

6 participants