rust Tauri前端服务器无法启动

nhaq1z21  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(390)

我最近一直在使用Tauri进行个人项目,我在两台不同的电脑上进行这个项目,因为我试图在业余时间从笔记本电脑上工作,如果我在外面,从我的桌面上工作。我从我的笔记本电脑上克隆了git repo,它工作得很好,但是如果我试图从我的桌面上再次运行它(在拉取项目更新后),就会发生这种情况:

如果我试图从我的笔记本电脑运行该项目,它仍然工作,没有改变代码或任何东西,我检查了端口没有被使用。
我用来运行项目的命令是网站上提供的命令:

npm run tauri dev

有人知道为什么会发生这种情况或如何解决这个问题吗?

44u64gxh

44u64gxh1#

我刚刚遇到了同样的问题。
事实证明,tauri.conf.json中的“devPath”与npm运行实际给我的不匹配。完整的输出消息如下所示:

VITE v4.1.4  ready in 682 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
        Warn Waiting for your frontend dev server to start on http://127.0.0.1:5173/...
        Warn Waiting for your frontend dev server to start on http://127.0.0.1:5173/...
        Warn Waiting for your frontend dev server to start on http://127.0.0.1:5173/...

在我的例子中,本地服务器是localhost,但tauri需要的是127.0.0.1
要解决这个问题,请编辑tauri.conf.json:

"build": {
    "beforeBuildCommand": "npm run build",
    "beforeDevCommand": "npm run dev",
    "devPath": "http://127.0.0.1:5173", // change to http://localhost:5173
    "distDir": "../build"
  },

相关问题