Closed helloimalastair closed 6 months ago
Been waiting on this issue for some months now as well. My workaround was to comment out [route]
definition from wrangler.toml
each time I was running my projects locally, but also needed to remember to un-comment before any commits/deploys...
Just discovered today that you can pass --routes=[]
on your command via package.json
scripts and it will overwrite the definition from wrangler.toml
.
So, the config may look like this:
wrangler.toml
:
name = "my-worker"
main = "src/worker.ts"
compatibility_date = "2023-10-23"
workers_dev = false
[route]
pattern = "worker.example.com"
custom_domain = true
package.json
:
{
"scripts": {
"dev": "wrangler dev --remote --routes=[]"
}
}
Hopefully we can get come kind fix, or at least, a flag to bypass routes
when using --remote
.
@helloimalastair @iksaku I'm unable to reproduce this in either the latest Wrangler or Wrangler 3.5. A couple questions to help debug this:
wrangler whoami
give you?)@penalosa
Just did some digging, and it looks like goalastair.com
is subject to a Bulk Redirect rule, and if I switch to www.goalastair.com
, it does work.
Also found a separate bug, in that when hitting the b
key to open in browser, it spawns www.goalastair.com:8787
Thanks @helloimalastair โin that case I'll close this issue. The hotkey bug is captured in https://github.com/cloudflare/workers-sdk/issues/3907, I think
@penalosa So wait, is it expected that --remote
doesn't work when rules are applied to the target? Or should that be documented somewhere?
--remote
should follow the same logic as deployed workers, as far as I know. Because redirect rules run before Workers, if you have:
source.example.com
to target.example.com
source.example.com
Accessing source.example.com
won't execute your worker. You'd have to give the worker a route of target.example.com
(the target of the redirect rule) for the worker to execute.
In the same way, I think it's expected behaviour that you need to provide www.goalastair.com/*
rather than goalastair.com/*
as the route if that's the ultimate target of the redirect rule, and the route set up on your deployed worker.
The OP may have a redirect rule set up that's not a best practice and is leading to this error...
I have a similar error, but without the redirect rules. My setup is this
If I have any routes in my wrangler.toml is when the OP's bug surfaces. If I add routes via the dashboard and comment out the routes in wrangler.toml, I'm able to get wrangler dev --remote running (or wrangler dev, press l to turn off local)
Interestingly, the error message is different if I use the --remote flag vs switching to remote. Switching to remote actually throws an error that was mentioned in a bug closed for Wrangler v2. I can provide more details here or elsewhere if this piques anyone's interest.
@lucas-pelton Would you be able to file a new issue with more details, and the exact error messages you're receiving? That sounds like a bug we should fix
Let me put together a proper test and report using a domain that's not running live services. It may be a minute, but I'll do it.
Hello @penalosa,
In my case, I have no bulk redirects nor page rules configured for the zone, so a redirection misconfiguration should not be the problem here.
Also, I'm using a subdomain for my worker, not the root domain, and the wrangler.toml
looks like this:
name = "my-worker"
main = "src/worker.ts"
compatibility_date = "2023-10-23"
workers_dev = false
[[r2_buckets]]
binding = "BUCKET"
bucket_name = "..."
preview_bucket_name = "..."
[route]
pattern = "worker.<my-domain>.com"
custom_domain = true
Any ideas?
@iksaku The Wrangler docs suggest you can't have these in the same config:
workers_dev = false
[route]
pattern = "worker.<my-domain>.com"
custom_domain = true
Specifically
If you change your routes in the dashboard, Wrangler will override them in the next deploy with the routes you have set in your wrangler.toml. To manage routes via the Cloudflare dashboard only, remove any route and routes keys from your wrangler.toml file. Then add workers_dev = false to your wrangler.toml file. https://developers.cloudflare.com/workers/wrangler/configuration/
Is this related to your use of wrangler dev --routes=[]
workaround?
I must've skipped that in the docs.
And yes, this is related to my workaround
@lucas-pelton those two items are fine to co-exist in a wrangler.toml
file. Those docs are specifically referring to if you want to only manage your routes through the Cloudflare dashboard. We can definitely clarify them if that's not clear though.
@iksaku what's the output you get from wrangler dev --remote
, and what's your account ID? I can take a look to see what might be going on?
(re-opening this to keep investigating)
@penalosa Sure!
My account ID is df4989e4945becf8236d033213f17af8
.
If I instead run using my workaround (wrangler dev --remote --routes=[]
) or directly comment out the [route]
definition in my wrangler.toml
file, the error in question disappears and the worker keeps working as intended.
Thank you!
@iksaku I get a very similar error log running wrangler dev --remote
, but if I run wrangler dev
and then press l
to switch from local to remote, the error is significantly different.
This JSON parsing error is the one that I mentioned in an earlier post that is similar to the Wrangler v2 bug at #2581 (at least in that they're trying to JSON.parse an HTML file when trying launch a remote dev server.
Stack trace:
โ [ERROR] Error while creating remote dev session: ParseError: Unexpected token <
at parseJSON
(/home/runcloud/wrangler-projects/telcom-processor/node_modules/wrangler/wrangler-dist/cli.js:119580:11)
at createPreviewSession
(/home/runcloud/wrangler-projects/telcom-processor/node_modules/wrangler/wrangler-dist/cli.js:150592:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async start
(/home/runcloud/wrangler-projects/telcom-processor/node_modules/wrangler/wrangler-dist/cli.js:150781:9)
My HTML file is a cloudflare error page - Error 1031: Improperly configured Workers Preview for dev-telcom.eaevsf.us. You may need to reinitialize.
Interestingly, I've commented out routes in wrangler.toml and I'm getting this error when switching to remote, but not when using the --remote
flag.
This is occurring on the sub.domain/ worker while I have a domain.com/ worker manually configured on the dashboard. (This is the live services setup, so I can't test the effect of taking down the domain.com/* route binding.
This is extremely frustrating as workerd is still encountering some issues that are not present when deployed. I'd really appreciate this being looked on more.
I often get:
โ ๏ธ [WARNING] worker failed to prewarm: Bad Gateway
OR
โ [ERROR] Error while creating remote dev session: ParseError: Unexpected token <
at parseJSON
The workaround using npx wrangler dev --remote --routes "[]"
does help :)
@lucas-pelton @iksaku @flexchar We've recently added some more error reporting into Wrangler, which should significantly help with debugging this. Would one of you be able to upload the error log that Wrangler outputs at the end of a run?
Hey Somhairle, I launched as typical and pressed l
to disable local mode receiving exact same error/output. I'm on the 3.25.0
version. Where should I look for the new logs?
If those are the ones from the file upon exit, then here you are - I redacted any hashes/ids of my own. :)
npm create cloudflare@latest -> Hello World Worker
wrangler.toml
name = "remote-dev-test"
main = "src/index.js"
compatibility_date = "2024-01-17"
account_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
workers_dev = false
route = { pattern = "worker.xxxxx.com", custom_domain = true }
GET https://worker.xxxx.com -> Hello World!
npx wrangler dev
โ
๏ธ wrangler 3.25.0
-------------------
โ Starting local server...
[wrangler:inf] Ready on http://localhost:8787
OK! Press 'l' to turn off local mode:
โ Shutting down local server...
โ [ERROR] Error while creating remote dev session: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
at JSON.parse (<anonymous>)
at parseJSON
(/home/runcloud/projects/wrangler/remote-dev-test/node_modules/wrangler/wrangler-dist/cli.js:119388:17)
at createPreviewSession
(/home/runcloud/projects/wrangler/remote-dev-test/node_modules/wrangler/wrangler-dist/cli.js:164891:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async start
(/home/runcloud/projects/wrangler/remote-dev-test/node_modules/wrangler/wrangler-dist/cli.js:165442:9)
npx wrangler dev --remote
โ
๏ธ wrangler 3.25.0
-------------------
[wrangler:inf] Ready on http://localhost:8787
Total Upload: 1.15 KiB / gzip: 0.63 KiB
OK!
turn ON local mode. OK turn OFF local mode. OK
npx wrangler dev Local starts OK, turn OFF local mode throws same error as above.
@lucas-pelton this should be fixed in #5107
Which Cloudflare product(s) does this pertain to?
Wrangler core
What version(s) of the tool(s) are you using?
3.5.0
What version of Node are you using?
20.5.1
What operating system are you using?
macOS Ventura 13.5
Describe the Bug
index.js
file:--remote
and--route
flags(with a zone you have access to):Waiting for connection... โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ [b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ /Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:30632 throw a; ^
Error: WebSocket was closed before the connection was established at WebSocket2.close (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:108521:11) at close (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:127122:14) at /Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:127230:7 at jh (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29688:15) at exports2.unstable_runWithPriority (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25660:16) at Pc (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:26308:16) at Qg (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29651:18) at /Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:29640:13 at V (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25585:22) at Timeout.w [as _onTimeout] (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:25420:13) Emitted 'error' event on WebSocket instance at: at emitErrorAndClose (/Project/Directory/node_modules/.pnpm/registry.npmjs.org+wrangler@3.5.0/node_modules/wrangler/wrangler-dist/cli.js:108968:17) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v20.5.1