5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 10:51:35 +08:00
wails/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/troubleshooting.mdx
github-actions[bot] ec19458c1b
docs: sync translations (#2616)
Co-authored-by: misitebao <misitebao@users.noreply.github.com>
2023-05-25 18:43:31 +10:00

173 lines
7.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 故障排除
各种故障排除技巧。
## `wails` 命令好像不见了?
如果您的系统报告缺少 `wails` 命令,请确保您已正确遵循 Go 安装指南。 通常,这意味着您的用户 home 目录中的 `go/bin` 目录不在 `PATH` 环境变量中。 通常情况下还需要关闭并重新打开任何已打开的命令提示符,以便安装程序对环境所做的更改反映在命令提示符中。
## 我的应用程序正在显示白屏/空白屏幕
检查您的应用程序是否包含正确目录中的资产。 在您的 `main.go` 文件中,您将拥有类似于以下代码的内容:
```go
//go:embed all:frontend/dist
var assets embed.FS
```
检查它是否 `frontend/dist` 包含您的应用程序资产。
### Mac
如果在 Mac 上发生这种情况,请尝试将以下内容添加到您的 `Info.plist`:
```xml
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
```
参考https://github.com/wailsapp/wails/issues/1504#issuecomment-1174317433
## Mac 应用程序无效
如果您构建的应用程序在 finder 中如下所示:
```mdx-code-block
<p className="text--center">
<img
src={
require("@site/static/img/troubleshooting/invalid_mac_app.png").default
}
/>
</p>
```
您的申请很可能 `info.plist` 是无效的。 更新 `build/<yourapp>.app/Contents/info.plist`文件 并检查数据是否有效,比如:检查二进制名称是否正确。 要保留更改,请将文件复制回 `build/darwin` 目录。
## 我的应用程序未在 Windows 资源管理器中显示正确的图标
如果您的应用程序未显示正确的图标,请尝试删除位于 `C:\Users\<您的用户名>\AppData\Local` 目录中的隐藏 `IconCache.db` 文件。 这将强制 Windows 重建图标缓存。
来源https://github.com/wailsapp/wails/issues/2360#issuecomment-1556070036
## 无法使用可变参数
如果您有使用可变参数定义的后端方法,例如:
```go
func (a *App) TestFunc(msg string, args ...interface{}) error {
// Code
}
```
像这样从前端调用此方法将失败:
```js
var msg = "Hello: ";
var args = ["Go", "JS"];
window.go.main.App.TestFunc(msg, ...args)
.then((result) => {
//do things here
})
.catch((error) => {
//handle error
});
```
解决方法:
```js
var msg = "Hello ";
var args = ["Go", "JS"];
window.go.main.App.TestFunc(msg, args)
.then((result) => {
//without the 3 dots
//do things here
})
.catch((error) => {
//handle error
});
```
致谢https://github.com/wailsapp/wails/issues/1186
## 我正在尝试安装Wails时获取代理错误
如果您遇到这样的错误:
```
"https://proxy.golang.org/github.com/wailsapp/wails/cmd/wails/@v/list": dial tcp 172.217.163.49:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
```
这可能是因为官方 Go Proxy 被阻止(中国用户报告了这一点)。 解决方案是手动设置代理,例如:
```
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
```
来源https://github.com/wailsapp/wails/issues/1233
## 没有生成正确的 TypeScript 类型
有时生成的 TypeScript 没有正确的类型。 `ts_type` 为了缓解这种情况,可以使用 struct 标签指定应该生成哪些类型。 有关详细信息,请阅读 [此](https://github.com/tkrajina/typescriptify-golang-structs#custom-types) 内容。
## 当我离开 `index.html`时,我无法在前端调用方法
如果您导航 `index.html` 到一个新的 html 文件,上下文将会丢失。 这可以通过将以下导入添加到 `<head>` 您导航到的任何新页面的部分来解决:
```html
<head>
<script src="/wails/ipc.js"></script>
<script src="/wails/runtime.js"></script>
</head>
```
来源https://github.com/wailsapp/wails/discussions/1512
## 运行 `wails dev` 出现 `too many open files` 错误
默认情况下macOS 最多只能打开 256 个文件。 这会影响 `wails dev` 命令 可以通过在终端中运行:`ulimit -n 1024` 来增加此限制。
FSNotify 正在 [寻求转移到苹果](https://github.com/fsnotify/fsnotify/issues/11)。 如果这不能很快完成,我们将创建自己的实现,在 [此处](https://github.com/wailsapp/wails/issues/1733) 跟踪。
## 我的 Mac 应用程序给了我奇怪的编译错误
一些用户报告看到编译错误,如下所示:
```shell
# github.com/wailsapp/wails/v2/internal/frontend/desktop/darwin
In file included from ../../pkg/mod/github.com/wailsapp/wails/v2@v2.0.0-beta.44.2/internal/frontend/desktop/darwin/callbacks.go:9:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12:
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:91:143: error: function does not return NSString
- (NSAttributedString *)localizedAttributedStringForKey:(NSString *)key value:(nullable NSString *)value table:(nullable NSString *)tableName NS_FORMAT_ARGUMENT(1) NS_REFINED_FOR_SWIFT API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0));
~~~~~~~~~~~~~~ ^ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:103:48: note: expanded from macro 'NS_FORMAT_ARGUMENT'
#define NS_FORMAT_ARGUMENT(A) __attribute__ ((format_arg(A)))
```
这 _通常_ 是由于您正在运行的操作系统版本和安装的 XCode 命令行工具的版本不匹配。 如果您看到这样的错误,请尝试将您的 XCode 命令行工具升级到最新版本。
如果重新安装 Xcode 命令工具仍然失败,您可以通过以下方式检查工具包所在的路径:
`xcode-select -p`
如果显示 `/Applications/Xcode.app/Contents/Developer` ,运行 `sudo xcode-select --twitter /Library/Developer/CommandLineTools`
来源https://github.com/wailsapp/wails/issues/1806 和 https://github.com/wailsapp/wails/issues/1140#issuecomment-1290446496
--
## 无法启动服务主机版本“x.x.x”与二进制版本“x.x.x”不匹配
最好将 `frontend/node_modules` 和 `frontend/package-lock.json` 添加到您的 `.gitignore` 中。 否则,当在另一台可能安装了不同版本 Node 的机器上打开您的存储库时,您可能无法运行您的应用程序。
如果发生这种情况,只需删除 `frontend/node_modules` 和 `frontend/package-lock.json` 并再次运行 `wails build` 或 `wails dev` 命令。
## 构建过程停留在“生成绑定”
绑定生成过程在特殊模式下运行应用程序。 如果应用程序有意或无意地包含一个无限循环(即在 `wails.Run()` 结束后不退出),这可能导致构建过程停留在绑定生成阶段。 请确保您的代码正确退出。