wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.25k stars 1.21k forks source link

Runtime Folder Deletes itself if you inject runtime manually to get access to wails runtime #2367

Open taylorlanglopez opened 1 year ago

taylorlanglopez commented 1 year ago

I got the same errors as

D:\Gitlab\mccl>wails dev
Wails CLI v2.0.0-beta.42 

Executing: go mod tidy -compat=1.17
Executing: wails generate module 
Installing frontend dependencies... 

> mccl@0.0.0 dev
> vite

  vite v2.9.15 dev server running at:

Vite Server URL: http://localhost:3000/ 
  > Local: http://localhost:3000/ 
  > Network: use `--host` to expose

  ready in 2370ms.

Running frontend DevWatcher command: 'npm run dev' 
Building application for development...
  - Installing frontend dependencies: Done. 
  - Compiling frontend: Done. 
  - Generating bundle assets: Done. 
  - Compiling application:
Build error - open D:\Gitlab\mccl\frontend\wailsjs\runtime\package.json: Access is denied.
No version running, build will be retriggered as soon as changes have been detected
Watching (sub)/directory: D:\Gitlab\mccl 
Using DevServer URL: http://localhost:34115
Using Frontend DevServer URL: http://localhost:3000/
Using reload debounce setting of 100 milliseconds

To develop in the browser and call your bound Go methods from Javascript, navigate to: http://localhost:34115
[Rebuild triggered] files updated 
  - Generating bundle assets: Done. 
  - Compiling application: Done. 

Added new directory to watcher: D:\Gitlab\mccl\frontend\wailsjs\runtime 
INF | Serving assets from frontend DevServer URL: http://localhost:3000/ 
DEB | WebView2 Runtime Version '104.0.1293.47' installed. Minimum version required: 94.0.992.31.
Error: mkdir D:\Gitlab\mccl\frontend\wailsjs\go\main: Access is denied. 
Development mode exited 
DevWatcher command exited!
DevWatcher command killed!

Situation

Under I monitored, I found some strange things.

  1. First, I need to run wails build to generate two folders go runtime.
  2. Then, run wails dev, at - Installing frontend dependencies: ... , it will delete the runtime folder.
  3. Then, wails cannot find the runtime and report errors.

Resolve

I try to give frontend\wailsjs\runtime\package.json the r&w permissions.

  1. wails build to get the runtime folder.
  2. Used the windows file properties to remove read.
  3. run chmod 777 frontend/wailsjs/runtime/package.json
  4. run wails dev
  5. Unfortunately, frontend\wailsjs\runtime\package.json still removed.

I try to keep the runtime folder.

  1. run wails dev
  2. get the runtime go folders.
  3. run chmod 777 frontend/wailsjs/runtime/package.json and use the windows file properties to remove read propertie of go and runtime between Executing: wails generate module and Installing frontend dependencies: ...
  4. Then wails will keep building, nothing reported.
  5. Then reported Error: mkdir frontend\wailsjs\go\main: Access is denied.
  6. I found the go folder removed.

I try to watch the go folder.

  1. run wails dev
  2. get the go folders.
  3. run chmod 777 frontend/wailsjs/runtime/package.json and use the windows file properties to remove read propertie of go and runtime between Executing: wails generate module and Installing frontend dependencies: ...
  4. Then, All errors are gone.

It's amazing, isn't it?

But then I edit files,

[Rebuild triggered] files updated 
  - Generating bundle assets: Done. 
  - Compiling application:  
Build error - open D:\Gitlab\mccl\frontend\wailsjs\runtime\package.json: Access is denied. 

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

taylorlanglopez commented 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 from the standard Vue router in order to host the View for each component.

Francisundermoon commented 1 year ago

I got the same error as u,did u work it out?

stffabi commented 1 year ago

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?

Francisundermoon commented 1 year ago

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!谢谢~

stffabi commented 1 year ago

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.

Francisundermoon commented 1 year ago

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

stffabi commented 1 year ago

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.

stffabi commented 1 year ago

@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.

Francisundermoon commented 1 year ago

@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

stffabi commented 1 year ago

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.

taylorlanglopez commented 1 year ago

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.

taylorlanglopez commented 1 year ago

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.

107295472 commented 1 year ago

@taylorlanglopez Have you solved it, I am also this Access is denied.

leaanthony commented 1 year ago

@taylorlanglopez any update?

taylorlanglopez commented 1 year ago

@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.

mooijtech commented 1 year ago

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.

haroflow commented 1 year ago

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.

go install github.com/wailsapp/wails/v2/cmd/wails@latest

wails doctor


Wails CLI v2.5.1

SUCCESS Done.

System

OS | Windows 10 Pro Version | 1909 (Build: 18363) ID | Go Version | go1.20.5 Platform | windows Architecture | amd64

Wails

Version | v2.5.1

Dependencies

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 |

Diagnosis

Your system is ready for Wails development! Optional package(s) installation details:

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.
...


Easiest way to test "go\main: Access denied" - It happens on `master` branch too. - Create a react-ts project: `wails init -n myproject -t react-ts` - Open `myproject` in vscode. - Open the file App.tsx, this will trigger vscode's TS analyzer. **Without this step the error doesn't happen.** - On my project's root: `go build -tags bindings -o wailsbindings.exe` - Run several times at random intervals: `.\wailsbindings.exe`. It fails sometimes, example: ``` PS C:\dev\myproject> go build -tags bindings -o wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Access denied. PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Access denied. PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Access denied. PS C:\dev\myproject> .\wailsbindings.exe PS C:\dev\myproject> .\wailsbindings.exe Error: CreateFile C:\dev\myproject\frontend\wailsjs\go\main: Access denied. ```

More info: Visual Studio Code, no TS extensions but I'll try disabling the others. Windows Defender disabled, no AVs installed.

leaanthony commented 1 year ago

Thanks for the info @haroflow - Do you think simply overwriting the files would be enough?

haroflow commented 1 year ago

@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.

haroflow commented 1 year ago

I spent a few more hours on this:

Windows 10. Windows Defender disabled.

leaanthony commented 1 year ago

Thanks for putting in the time on this 🙏 Sounds promising!

CLincat commented 5 months ago

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:

  1. Assuming "main-2" is your application, when you run the wails dev command, you get two errors. (white font + red font) 01

  2. To fix this bug, you'll need to create another project. For example wails init -n test -t svelte 02

  3. After that, you can go to the frontend folder and download the npm package you need. 03

  4. 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. 04

  5. Assuming "main-2" is your application, copy the project to the "test" directory. (Except for the build and frontend folders) 05

  6. Delete the frontend/src folder in the test project. 06

  7. Similar to step 5, copy the frontend/src folder. 07

  8. 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. 08

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?

CLincat commented 5 months ago

Also, when encountering a fatal error with red fonts, the command wails dev fails to work, but the command wails build works fine.

leaanthony commented 5 months ago

Are your Dev and non Dev dependencies the same?

CLincat commented 5 months ago

Yes, they are the same.

CLincat commented 5 months ago

I retested "testing 2.2" and found two things in common.

  1. Project "main-3" is working fine, I copied it as "test". 51

  2. Fatal error with red font after using the command wails dev in project "test". By contrasting, I found two differences. 52

    2.1 The frontend/wailsjs/runtime/ folder is deleted. 53

    2.2 The frontend/node_modules/.vite/deps/ folder is deleted and replaced by deps_temp. 54

  3. deps/ and deps_temp/. 55 56

powershell_CJnneyavGS

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.