Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

wrangler dev should not fail if it can't open the browser #2180

Closed
stevenpack opened this issue Jan 7, 2022 · 3 comments
Closed

wrangler dev should not fail if it can't open the browser #2180

stevenpack opened this issue Jan 7, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@stevenpack
Copy link

🐛 Bug report

Describe the bug

wrangler dev assumes it's running in an interactive environment, which is not always true. For example, running on Github codespaces, it's in a remote docker image. The way other frameworks work is they open the local port and codespaces detects that and magically port forwards and gives you a URL to use. E.g. I can run npm run serve on a Vue project, it opens https://localhost:8080 and then access that on my browser via a URL like https://my-project-xxv4q6php6vw-8080.githubpreview.dev over port 80.

It doesn't work with wrangler though, because it tries to pop up the browser with xdg-open and fails hard when that doesn't work the process dies.

$ npx wrangler pages dev ./dist
Compiling worker to "/tmp/functionsWorker.js"...
Compiled Worker successfully.
Serving at http://127.0.0.1:8788/
/workspaces/eth-registrar/app/web/node_modules/wrangler/wrangler-dist/cli.js:27072
            throw ex;
            ^

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

Reproduce the bug

A list of steps to reproduce the bug.

  1. Open any repo with a Cloudflare worker using https://github.com/features/codespaces
  2. Run npx wrangler pages dev <your output dir>
  3. See error 'xdg-open' failed, and note that there is nothing running.

Expected behavior

  1. Run npx wrangler pages dev <your output dir>
  2. See the url in the console output e.g. http://127.0.0.1:8788 as per Wrangler Login should print the URL to the console in addition to opening it #1544
  3. Don't fail on the error. Keep the process running with so codespaces sees the open port and allows me to access it the browser on my local machine.

Environment and versions

Fill out the following information about your environment.

  • operating system: uname -a Linux codespaces_7ecb11 5.4.0-1063-azure #66~18.04.1-Ubuntu SMP Thu Oct 21 09:59:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • output of wrangler -V: $ npx wrangler -v 0.0.7
  • output of node -v: v16.9.1
  • content of wrangler.toml: none.

NOTE: This is pretty specific to Github code spaces, but other frameworks 'just work'. It would be great if wrangler did too.

@stevenpack stevenpack added the bug Something isn't working label Jan 7, 2022
@stevenpack
Copy link
Author

With wrangler login, it's closer... you see get:

💁  Opened a link in your default browser: https://dash.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&state=eEWRL1p2O5gb5h2g-hG9sg&code_challenge=4zwFTMKwKcQXVIsonmhZ_al7GQGfU84DRgEUbv13eiQ&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread+user%3Aread+workers%3Awrite+workers_kv%3Awrite+workers_routes%3Awrite+workers_scripts%3Awrite+workers_tail%3Aread+zone%3Aread+offline_access
Error: Failed to receive authorization code from local HTTP server. Please run `wrangler login` again. If the error persists, consider reporting the issue through `wrangler report`.

And codespaces does port forward, but process fails with Failed to receive authorization code from local HTTP server before you can actually enter the url in your local browser.

@threepointone
Copy link
Contributor

This is a wrangler2 issue, and is being tracked here cloudflare/workers-sdk#23. Closing this issue.

@threepointone
Copy link
Contributor

regarding opening the browser, that was fixed in cloudflare/workers-sdk#211. We'll do a publish next week that includes that fix, or you could try with wrangler@alpha.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants