Open taylorlanglopez opened 1 year ago
I have also granted full permissions to everyone just like this person. I have the same issue where the runtime folder just deletes itself if I want to have working code for wails build.
This is still broken. The runtime folder will always delete itself if you want to inject the runtime into a component for example.
Vue Component (Works but breaks wails dev)
<script setup lang="ts">
import * as wailsrt from '../../wailsjs/runtime/runtime'
....
wailsrt.EventsOn("progress", (proginc: string) => {
//code to update a progress bar
}
...
</script>
Vue Component (Doesn't work and throws a compiler error on type-check)
<script setup lang="ts">
....
window.runtime.EventsOn("progress", (proginc: string) => {
//code to update a progress bar
}
...
</script>
The second example is "correct" according to the documentation, but it just throws a compiler error.
/src/components/File.vue(48,8): error TS2339: Property 'runtime' does not exist on type 'Window & typeof globalThis'
I'm really lost as to how I get access to the runtime inside a component without breaking wails dev.
My structure is src/components src/views App.vue main.ts
I have not modified main.ts (main.js) at all, I added a router to App.vue and il8n.
My App.vue has a
I got the same error as u,did u work it out?
Thanks for using Wails and bringing up this issue.
Unfortunately AFAIK none of the Core Dev were ever able to reproduce this. I've also followed your reproduction guide and added a vue component with the specified import and the issue didn't occur here.
I suspect this is a timing issue between vite and the creation of the runtime/bindings. Nevertheless I've created a Draft PR which should improve this situation. Would it be possible for you to give PR #2372 a try according to this guide?
Thanks for using Wails and bringing up this issue.
Unfortunately AFAIK none of the Core Dev were ever able to reproduce this. I've also followed your reproduction guide and added a vue component with the specified import and the issue didn't occur here.
I suspect this is a timing issue between vite and the creation of the runtime/bindings. Nevertheless I've created a Draft PR which should improve this situation. Would it be possible for you to give PR #2372 a try according to this guide?
Wow,it worked!!!tks again for the effort u guys made!谢谢~
Awesome, thanks for your feedback and testing it.
Let's see what the other people say that are suffering from this and if it does fix it we could take the PR out of draft.
Awesome, thanks for your feedback and testing it.
Let's see what the other people say that are suffering from this and if it does fix it we could take the PR out of draft.
after applying the new PR u proposed,the mode of dev works well,but when i altered my code ,the dev watcher retrigerred that error again,differed from the last message ,it saysthat Failed to resolve import "../../wailsjs/runtime"(Runtime Folder Deletes itself) ,which force me to restart the dev mode onemore time
Hmm, I had suspected something like that might happen. I really think there's something that vite is locking there when deleting the files and recreating them. My first impression was that this only happens during startup because starting vite and compiling the app might run in parallel.
We could try to skip rebuilding the runtime, because that won't ever change during reload. Hopefully there's not the same problem with the no normal bindings. Will let you know when the PR is updated.
@chuyijia could you please try the updated version of the PR? Please also make sure to have the correct replace in your go.mod
in place, since the latest changes also affect the binary itself.
@chuyijia could you please try the updated version of the PR? Please also make sure to have the correct replace in your
go.mod
in place, since the latest changes also affect the binary itself.
Gladly,the lose of runtime folder is no concern anymore(your lastest pr worked).Sadly, the go/module folder disappeared as follow(the error show that Failed to resolve import "../wailsjs/go/module/App" from "utils\bsc.ts". Does the file exist?) 0.0
Seems like Vite (at least on some systems) has problems when a folder is deleted and recreated with new content. Seems like we probably need to sync that folders instead of just deleting and recreating them to work around this.
Unfortunately, updating my wails is kind of a hassle due to corporate constraints. It takes me multiple days to get stuff updated on the machine where I'm experiencing issues. I can try and recreate my issue with runtime injection and the folder deletion in a public GitHub repo, but that requires me rewriting a significant amount of code. I'll try and get it to this thread by tomorrow. I will also try the PR when I can, thanks for your help.
This is a pure permissions issue, I haven't tracked down what permission scheme makes the wails dev runtime folder mess itself up, but I cannot replicate the same issue outside of my corporate network. I am going to try the PR you posted today to see if the PR can fix it on my work network.
@taylorlanglopez Have you solved it, I am also this Access is denied.
@taylorlanglopez any update?
@taylorlanglopez any update?
Not yet. Unfortunately I've been travelling for work and haven't been on that isolated network for awhile. So I haven't been able to look at the permissions structure.
Also having this issue on Windows, the wailsjs/runtime
directory is not being created.
panic: open <path>\wailsjs\runtime\package.json: Access is denied
The wailsjs
has drwxr-xr-x
permissions (755).
Wails CLI version v2.5.1
.
Works fine on Linux (the wailsjs
directory was pushed to Git from Linux).
Edit: This problem occurs in a Virtual Machine (VirtualBox), but a dual boot seems to work fine.
Edit2: I will setup Wails for local IDE development tomorrow and have a go at finding the cause. Should really be using stack traces (
https://github.com/rotisserie/eris or https://github.com/pkg/errors instead of err.Error()
, makes debugging much easier.
Edit3: Got a stack-trace, need to go deeper...
Build error: exit status 2
panic: Failed to start Wails: open C:\Users\user\Documents\goforensics\frontend\wailsjs\runtime\package.json: Access is denied.
goroutine 1 [running]:
main.main()
C:/Users/user/Documents/goforensics/goforensics.go:142 +0x111f
github.com/wailsapp/wails/v2/pkg/commands/build.GenerateBindings
C:/Users/user/Documents/wails/v2/pkg/commands/build/build.go:232
github.com/wailsapp/wails/v2/pkg/commands/build.Build
C:/Users/user/Documents/wails/v2/pkg/commands/build/build.go:129
github.com/wailsapp/wails/v2/cmd/wails/internal/dev.restartApp
C:/Users/user/Documents/wails/v2/cmd/wails/internal/dev/dev.go:285
github.com/wailsapp/wails/v2/cmd/wails/internal/dev.Application
C:/Users/user/Documents/wails/v2/cmd/wails/internal/dev/dev.go:122
main.devApplication
C:/Users/user/Documents/wails/v2/cmd/wails/dev.go:36
reflect.Value.call
C:/Program Files/Go/src/reflect/value.go:586
reflect.Value.Call
C:/Program Files/Go/src/reflect/value.go:370
github.com/leaanthony/clir.(*Command).NewSubCommandFunction.func1
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:350
github.com/leaanthony/clir.(*Command).run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:108
github.com/leaanthony/clir.(*Command).run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:87
github.com/leaanthony/clir.(*Cli).Run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/cli.go:73
main.main
C:/Users/user/Documents/wails/v2/cmd/wails/main.go:96
runtime.main
C:/Program Files/Go/src/runtime/proc.go:250
runtime.goexit
C:/Program Files/Go/src/runtime/asm_amd64.s:1598
github.com/wailsapp/wails/v2/pkg/commands/build.Build
C:/Users/user/Documents/wails/v2/pkg/commands/build/build.go:131
github.com/wailsapp/wails/v2/cmd/wails/internal/dev.restartApp
C:/Users/user/Documents/wails/v2/cmd/wails/internal/dev/dev.go:285
github.com/wailsapp/wails/v2/cmd/wails/internal/dev.Application
C:/Users/user/Documents/wails/v2/cmd/wails/internal/dev/dev.go:122
main.devApplication
C:/Users/user/Documents/wails/v2/cmd/wails/dev.go:36
reflect.Value.call
C:/Program Files/Go/src/reflect/value.go:586
reflect.Value.Call
C:/Program Files/Go/src/reflect/value.go:370
github.com/leaanthony/clir.(*Command).NewSubCommandFunction.func1
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:350
github.com/leaanthony/clir.(*Command).run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:108
github.com/leaanthony/clir.(*Command).run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/command.go:87
github.com/leaanthony/clir.(*Cli).Run
C:/Users/user/go/pkg/mod/github.com/leaanthony/clir@v1.3.0/cli.go:73
main.main
C:/Users/user/Documents/wails/v2/cmd/wails/main.go:96
runtime.main
C:/Program Files/Go/src/runtime/proc.go:250
runtime.goexit
C:/Program Files/Go/src/runtime/asm_amd64.s:1598
Edit4: I am unable to get the stack-trace produced by internal/app/app_bindings.go
which is called by compiling with the bindings
flag in pkg/commands/bindings.go
.
I was also trying to trace these errors, they break the react-ts/angular workflow for me on Windows 10... might happen with all TS templates, not sure.
Error: open C:\dev\myproject\frontend\wailsjs\runtime\package.json: Access denied.
Seems to be caused by vite, as already mentioned. PR 2372 fixes on initialization, but when changing app.go
I get:
• Generating bindings: 2023/06/25 15:38:22 Error: CreateFile C:\dev\wails-react\frontend\wailsjs\go\main: Acesso negado.
...
[vite] Internal server error: Failed to resolve import "../wailsjs/go/main/App" from "src\App.tsx". Does the file exist?
Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Access denied.
This one happens after I open App.tsx on vscode, seems to be caused by vscode's TS analyzer. Happens on master
branch too.go install github.com/wailsapp/wails/v2/cmd/wails@latest
wails doctor
Wails CLI v2.5.1
SUCCESS Done.
OS | Windows 10 Pro Version | 1909 (Build: 18363) ID | Go Version | go1.20.5 Platform | windows Architecture | amd64
Version | v2.5.1
Dependency | Package Name | Status | Version WebView2 | N/A | Installed | 114.0.1823.51 Nodejs | N/A | Installed | 16.13.2 npm | N/A | Installed | 8.1.2 upx | N/A | Available | nsis | N/A | Available |
Your system is ready for Wails development! Optional package(s) installation details:
nsis : More info at https://wails.io/docs/guides/windows-installer/
♥ If Wails is useful to you or your company, please consider sponsoring the project: https://github.com/sponsors/leaanthony
wails init -n myproject -t react-ts
cd .\myproject\
wails dev
...
• Generating bindings:
2023/06/24 23:53:24 Error: open C:\dev\myproject\frontend\wailsjs\runtime\package.json: Acesso negado.
...
Ctrl+C
code .
On vscode, open frontend/src/App.tsx. Go back to powershell
wails dev
Wails CLI v2.5.1
Executing: go mod tidy
• Generating bindings:
2023/06/24 23:55:01 Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Acesso negado.
...
More info: Visual Studio Code, no TS extensions but I'll try disabling the others. Windows Defender disabled, no AVs installed.
Thanks for the info @haroflow - Do you think simply overwriting the files would be enough?
@leaanthony You're welcome!
I was thinking about it, not sure if the lock will allow that... don't have much experience with locks on Windows but it's worth a shot.
Some other options, just to throw it out there:
I also wasn't able to find the exact code that fails yet, will give another try this week.
I spent a few more hours on this:
Tried disabling all extensions in vscode, didn't help.
Tried to "retry on failure" wherever wails removed/created the bindings just to get a sense of what is going on, and it helped a bit, but it's still failing with: [vite] Internal server error: Failed to resolve import "../wailsjs/go/main/App" from "src\App.tsx". Does the file exist?
.
So it seems that Vite tries to read files between wails' changes which is problematic.
Here are the changes for reference, but it's terrible: https://gist.github.com/haroflow/34f58450b148cf243b5b8d38c54619cd
Knowing that vite is doing this, I tried a few vite.config.ts
options:
build: { watch: { buildDelay: 2000 } }
: doesn't work, wails dev
gets stuck on Compiling frontend
.server: { watch: { usePolling: true } }
: seems to have fixed all errors for me, even with the latest Wails. Needs more testing.Windows 10. Windows Defender disabled.
Thanks for putting in the time on this 🙏 Sounds promising!
I seem to have found a fix step, but I don't know how it works or if it works for anyone else. I did a test for this:
Assuming "main-2" is your application, when you run the wails dev
command, you get two errors. (white font + red font)
To fix this bug, you'll need to create another project. For example wails init -n test -t svelte
After that, you can go to the frontend folder and download the npm package you need.
Use the command wails dev to run the initial application. This may load something, if this step is missing, it may result in the repair failing. (I don't know how it works) We can see an error message in white font, but this does not affect the running.
Assuming "main-2" is your application, copy the project to the "test" directory. (Except for the build
and frontend
folders)
Delete the frontend/src folder in the test project.
Similar to step 5, copy the frontend/src folder.
Use the command wails dev
to run the brand new "test" project.
We can see an error message in white font, but this does not affect the running.
During testing, I found that a lot of behaviors lead to fatal errors in red fonts:
2.1 Using the npm install
command to get packages while developing a project, and then running the wails dev
command produces a fatal error with red fonts. If you use npm install
to get these packages ahead of time, and then develop your project, you won't get an error. ( The question of the order of execution )
2.2 "main-2" works fine, copy it as "main-3". All files for "main-2" and "main-3" are the same, but the copied "main-3" produces a fatal error with red font when running wails dev
. ( Problems when copying project folders )
Combining step 4 with testing 2.1, I think it might be an issue with npm package loading?
Also, when encountering a fatal error with red fonts, the command wails dev
fails to work, but the command wails build
works fine.
Are your Dev and non Dev dependencies the same?
Yes, they are the same.
I retested "testing 2.2" and found two things in common.
Project "main-3" is working fine, I copied it as "test".
Fatal error with red font after using the command wails dev
in project "test". By contrasting, I found two differences.
2.1 The frontend/wailsjs/runtime/
folder is deleted.
2.2 The frontend/node_modules/.vite/deps/
folder is deleted and replaced by deps_temp
.
deps/
and deps_temp/
.
I found that my previous projects (e.g. "main-2") had the same wrong behavior 2.1 + 2.2
Project main-3 works fine and does not result in a deps_temp
directory during the wails dev
process.
I got the same errors as
Situation
Under I monitored, I found some strange things.
wails build
to generate two foldersgo
runtime
.wails dev
, at- Installing frontend dependencies: ...
, it will delete theruntime
folder.runtime
and report errors.Resolve
I try to give
frontend\wailsjs\runtime\package.json
the r&w permissions.wails build
to get theruntime
folder.windows file properties
to removeread
.chmod 777 frontend/wailsjs/runtime/package.json
wails dev
frontend\wailsjs\runtime\package.json
still removed.I try to keep the
runtime
folder.wails dev
runtime
go
folders.chmod 777 frontend/wailsjs/runtime/package.json
and use thewindows file properties
to removeread propertie
ofgo
andruntime
betweenExecuting: wails generate module
andInstalling frontend dependencies: ...
Error: mkdir frontend\wailsjs\go\main: Access is denied.
go
folder removed.I try to watch the
go
folder.wails dev
go
folders.chmod 777 frontend/wailsjs/runtime/package.json
and use thewindows file properties
to removeread propertie
ofgo
andruntime
betweenExecuting: wails generate module
andInstalling frontend dependencies: ...
It's amazing, isn't it?
But then I edit files,
I found
runtime
deleted again.sad...
So I guess this is a question of permissions.
Originally posted by @Maicarons2022 in https://github.com/wailsapp/wails/issues/1752#issuecomment-1219007533