antoine-coulon / skott

All-in-one devtool to automatically analyze, search and visualize project modules and dependencies from JavaScript, TypeScript (JSX/TSX) and Node.js (ES6, CommonJS)
MIT License
669 stars 25 forks source link

webapp display mode throws error in wsl #107

Closed mojabyte closed 1 year ago

mojabyte commented 1 year ago

Running in WSL (Windows Subsystem Linux) throws an error when trying to open the webapp URL:

$ skott --displayMode=webapp

 Running Skott from current directory: -

 Processed 183 files (1885.137ms)

 βœ“ no circular dependencies found (depth=Infinity)

 Third-party dependencies: ❌

 --> Use --trackThirdPartyDependencies to enable tracking.

 Built-in dependencies: ❌

 --> Use --trackBuiltinDependencies to enable tracking.

 Type-level only dependencies: βœ…

 Prefetching data... 

 πŸ’» Opened skott webapp on http://127.0.0.1:41707

 Skott exited with code 1
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://127.0.0.1:41707' ]
}

Node.js v18.18.0
antoine-coulon commented 1 year ago

Hello @HassanMojab, thanks for the heads up!

It seems that it comes from an upstream problem on WSL https://github.com/microsoft/WSL/issues/8892. As I'm using a fork of openurl I will do two things:

  1. Try to find a workaround for WSL to be able to keep that auto open behavior (some workarounds are discussed here). The thing is I'm not running WSL myself, so will be hard for me to reproduce and be sure to fix the problem.

  2. Fix the uncaught exception in the library I'm using that should be handled properly and not make the process crash (upstream, not in skott). This would have for consequence to not open the browser automatically but would allow the application to be accessible anyway.

antoine-coulon commented 1 year ago

@HassanMojab, I just released an attempt to a fix for WSL in 0.30.1.

In the best scenario wslview works as expected and the browser will be automatically opened.

In the worst scenario, wslview does not work but now the error is properly managed so the process won't crash and you'll be able to access the application manually. If you have any suggestion to properly use wslview or an alternative as I'm not familiar at all with it, feel free to re-open the issue and keep the discussion going on.

Thanks

mojabyte commented 1 year ago

The wslview is not installed on wsl by default. I've found this command for opening a URL on the Windows default browser from wsl:

cmd.exe /C start "http://127.0.0.1:40000" > /dev/null 2>&1
antoine-coulon commented 1 year ago

Ah fml I was too confident about it πŸ˜… I'll add your cmd.exe in another PR as a primary target when being in WSL. Thanks for the hint! I reopen the issue

antoine-coulon commented 1 year ago

Hey again @HassanMojab,

Just released 0.30.2 switching for cmd.exe instead of wslview. Could you please confirm me that it now works well please? I'll wait until then to close the issue.

Thanks!

mojabyte commented 1 year ago

It works! the browser opens with the given URL 127.0.0.1:<port>

But unfortunately, there is still an issue :( 127.0.0.1 is considered as localhost in linux, but not in windows. So the ports of wsl are forwarded to the localhost of the windows and can be accessed by localhost:<port> but not by 127.0.0.1:<port>.

I think you simply can use localhost instead of 127.0.0.1 in the code like other cross-platform applications, and it should solve this problem.

antoine-coulon commented 1 year ago

Glad to hear that the auto opening is working as expected on WSL :)

About localhost, I was not aware of that and I thought WSL would manage this transparently. Thanks for the hint! I just changed 127.0.0.1 to localhost on all platforms in 0.30.3.

Could you please test it and confirm me that it now fully works? Thanks again for your reactivity and contribution, highly appreciate it

mojabyte commented 1 year ago

Now it fully works!

antoine-coulon commented 1 year ago

Thanks again for confirming that @HassanMojab!