tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
78.1k stars 2.31k forks source link

[bug] tauri failed to load localhost dev server #9699

Closed NessajCN closed 1 week ago

NessajCN commented 1 week ago

Describe the bug

Created a new project with create-tauri-app cli tool. cd project && npm i npm run tauri dev The Rust part compiled fine. The frontend window indicated Connection terminated unexpectedly. Console logged Failed to load resource: Connection terminated unexpectedly http://localhost:1420/ (I use the React template so it's Vite port 1420 here) Open http://localhost:1420 in browser, success. Modified src-tauri/tauri.conf.json from

  "build": {
    "beforeBuildCommand": "npm run build",
    "beforeDevCommand": "npm run dev",
    "devUrl": "http://localhost:1420",
    "frontendDist": "../dist"
  },

to

  "build": {
    "beforeBuildCommand": "npm run build",
    "beforeDevCommand": "npm run dev",
    "devUrl": "http://127.0.0.1:1420",
    "frontendDist": "../dist"
  },

Same behavior. Changed build.devUrl to https://google.com. Contents from webpage showed up.

Modified vite.config.ts to add a host:

  server: {
    // Add my local ip address as host 
    host: "192.168.3.100",
    port: 1420,
    strictPort: true,
    watch: {
      // 3. tell vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"],
    },
  },

Also set build.devUrl to http://192.168.3.100:1420 The front window loaded successfully.

So it appeared that my tauri refused to load any resource from a localhost or 127.0.0.1 host as its dev server. I've checked /etc/hosts , pinged localhost, visited localhost contents from browser. Everything is fine. Even started an nginx daemon and set build.devUrl to http://localhost yet failed to load, while http://192.168.3.100 works perfect.

Tried both v2 and v1 version of tauri. Exact the same problem.

I am now totally confused what could be the reason tauri does not load localhost. I don't know if anyone could reproduce that, as I have tried to reproduce that in other machines and everyone else seemed ok with localhost. I use Archlinux with KDE Plasma 6.0.4 in wayland. Any suggestion is appreciated.

Reproduction

No response

Expected behavior

No response

Full tauri info output

> tauritest@0.0.0 tauri
> tauri info

[✔] Environment
    - OS: Arch Linux Unknown X64
    ✔ webkit2gtk-4.1: 2.44.1
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (2024-05-07)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 21.7.3
    - npm: 10.7.0
    - bun: 1.0.7

[-] Packages
    - tauri [RUST]: 2.0.0-beta.18
    - tauri-build [RUST]: 2.0.0-beta.14
    - wry [RUST]: 0.39.4
    - tao [RUST]: 0.27.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.11
    - @tauri-apps/cli [NPM]: 2.0.0-beta.16

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

NessajCN commented 1 week ago

Solved. Installed a webkit2gtk based browser (luakit). Also failed to load localhost yet reminds me of system proxy maybe in use. Remove the proxy setting of KDE system setting and the problem is solved.