wrangler-legacy icon indicating copy to clipboard operation
wrangler-legacy copied to clipboard

[wrangler dev] HTTP status client error (400 Bad Request)

Open mw866 opened this issue 4 years ago • 16 comments

🐛 Bug Report

Environment

  • operating system:
Darwin xxxxx 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
  • output of rustc -V: Not available
  • output of node -v: v15.3.0
  • output of wrangler -V: wrangler 1.12.2
  • contents of wrangler.toml:
type = "javascript"
account_id = "78ab5493f4bafb4b7b027542995bb87d"
workers_dev = false
route = "httpbin.chriswang.me/anything/wrangler"
zone_id = "2a0086b5c6e89ce13797f1af8c8fa88a"

Steps to reproduce

Run wrangler dev

What did you expect to see?

What's described in the blog post

What did you see instead?

$ wrangler dev
Error: HTTP status client error (400 Bad Request) for url (https://chriswang.me/cdn-cgi/workers/preview/?s0=AfHYCyYtW01NMCmfbyLEEQ__pEX_5IXQjlCWo5pLoB06J0hYK8Mim0aocaUyLAPOOVlAQtHsT8yJwMh7B-FJ2L8obFpEKOXk3hTtfkZH53CmGv-OhnS8tFsS_d7PUNRhOgFaS0i4vzu6yiD1AJ9NUf31Aa_jQbq_7WRgSYwYroYDozTal-tF4ncVKRH4Do63KZrtq8lr9H2yLXgqvoBtqnOWpEb_envUse9PdDNQnr-DtWFXC2OUnm4_6biNLUtZP-rYbGXJoHICixMg_v-SLJs)

In contrast, wrangler preview works as expected.

$ wrangler preview
💁  Opened a link in your default browser: https://cloudflareworkers.com/?hide_editor#1d64ed6f85411b047b005ac33f8edc74:https://example.com/
👷  Your Worker responded with: Hello worker!

mw866 avatar Dec 14 '20 06:12 mw866

The issue persists on the latest verison.

wrangler -V
👷 ✨  wrangler 1.12.3

mw866 avatar Dec 28 '20 08:12 mw866

I was able to work around this by deleting ~/.wrangler/config

wilsonianb avatar Jan 08 '21 00:01 wilsonianb

Thanks. I just tried. Unfortunately, deleting ~/.wrangler/config did not help with my case.

mw866 avatar Jan 08 '21 08:01 mw866

I faced the exact same problem after adding my root domain to Cloudflare Pages as custom domain. Deleting ~/.wrangler/config did not fix the problem.

Kynson avatar Feb 18 '21 04:02 Kynson

I faced this issue and it ended up being user error... The account id I had in my wrangler.toml file in my project was wrong. Might not be in your case but worth double checking the low hanging fruit IMO.

infosec-shinobi avatar Mar 10 '21 12:03 infosec-shinobi

Same bug here. I cannot debug it anymore. Any solutions ?

medmin avatar Jul 17 '21 22:07 medmin

OK, I got a solution. The command wrangler dev --host=localhost works.

medmin avatar Jul 23 '21 06:07 medmin

Same issue here using localhost works but that doesn't let me use the KV-store so not really an option

version: wrangler 1.19.0

wrangler dev --verbose does not give any additional info

Fixed: I didn't specify any environment and so a variable was undefined in my script. Error reporting could be improved

reinoldus avatar Aug 03 '21 13:08 reinoldus

Had the same issue. Spent hours & hours debugging and re-doing login etc when in practice this line broke it in a file where it's used exactly the same in another

const DataAPI = require('./data');

kokarn avatar Aug 17 '21 11:08 kokarn

I had an error in my secret, it was not parsing correctly as JSON.

Ironically, can't be detected by wrangler build, only found it when trying wrangler publish, and wrangler dev fails with the HTTP error...

Also note: wrangler dev --host=localhost does not use authentication, so things like secrets and KV not working.

mattlockyer avatar Aug 22 '21 16:08 mattlockyer

Same issue here wrangler 1.19.0 image

rootlinux2 avatar Aug 26 '21 18:08 rootlinux2

Changing type = javascript to type = webpack in wrangler.toml "fixed" this issue for me. Apparently, it was somehow caused by using module syntax import / export for local files in my case.

fspoettel avatar Aug 28 '21 10:08 fspoettel

I have the same issue. Even on the latest wrangler (1.19.3), the command wrangler dev fails with the same error Error: HTTP status client error (400 Bad Request) when specifying a route in wrangler.toml. Without a route and with workers_dev = true it works fine. This may be a problem in wrangler's interaction with custom domains.

fabpopa avatar Oct 07 '21 13:10 fabpopa

after reading this whole thread, this was caused by a compiler error for me. wrangler needs some better error reporting

noah-seltzer avatar Oct 28 '21 01:10 noah-seltzer

Same here, circular requires for example broke it without any trace for me

kokarn avatar Oct 28 '21 06:10 kokarn

In my case, the worker route is configured at a subdomain (jsonp.afeld.me), while my second-level domain (afeld.me) is configured to be DNS only. wrangler dev tries to access access https://afeld.me/cdn-cgi/workers/preview/?..., which then gives a 404 from my [second-level domain] hosting provider. Two workarounds:

  • Running wrangler dev --unauthenticated

  • Re-enabling *.wrangler.dev and moving my route configuration in the wrangler.toml under an environment, like so:

    workers_dev = true
    
    [env.production]
    route = "jsonp.afeld.me/*"
    

afeld avatar Jan 18 '22 04:01 afeld

👋 Thanks for reporting this issue! Wrangler v1 is now deprecated and support is only being provided for critical updates or security concerns. As such, we are closing this issue.

New versions of Wrangler are maintained in the workers-sdk repo. If you are running into a similar issue with wrangler v2, please report it in the workers-sdk repo. For more info about wrangler v1 deprecation, please check out our blog post.

mrbbot avatar Feb 27 '23 16:02 mrbbot