Wails dev执行报错:无法找到wails.json,请求协助排查
Wails + Svelte 嵌套组件开发报错解决
问题背景
基于Wails + Svelte的Hello World项目,在开始嵌套组件开发前,wails dev或wails build运行完全正常。但在App.svelte同目录(...\1-hello_world\frontend\src)创建Nested.svelte组件后,出现异常提示:
- 在项目根目录
...\1-hello_world执行wails dev,终端提示找不到根目录下的wails.json,但该文件实际存放在...\1-hello_world\frontend\wails.json - 在
frontend子目录执行wails dev,终端提示no Go files in ...\1-hello_world\frontend
代码文件内容
App.svelte
<script lang="ts"> import Nested from "./Nested.svelte"; let src = "./src/assets/images/bobby.png"; const title = "Mr."; const height = "small"; </script> <h3>Title of App - Hello Again {title.toUpperCase()} World</h3> <p>Paragraph styling is scoped.</p> <Nested /> <style> p { color: goldenrod; font-family: "Comic Sans MS", cursive; font-size: 2em; } </style>
Nested.svelte
<script lang="ts"> </script> <p>This is the nested paragraph.</p>
解决步骤
- 迁移配置文件到项目根目录:Wails框架要求
wails.json必须放在项目根目录(即...\1-hello_world),将frontend/wails.json剪切到根目录下。 - 修正配置文件路径指向:打开根目录的
wails.json,确认frontend.dir字段正确指向前端子目录:"frontend": { "dir": "./frontend", "installCommand": "npm install", "buildCommand": "npm run build", "devServerCommand": "npm run dev" } - 重新执行开发命令:回到项目根目录,运行
wails dev,此时Wails会正确读取配置文件,调用前端开发服务,嵌套组件也能正常加载。
内容的提问来源于stack exchange,提问作者Mark Spindler
相关产品推荐
相关产品推荐

