cloudflare / wrangler-legacy

🤠 Home to Wrangler v1 (deprecated)
https://workers.cloudflare.com
Apache License 2.0
3.2k stars 337 forks source link

wrangler dev throws Error: EOF while parsing a value at line 1 column 0 #1583

Closed danbars closed 2 years ago

danbars commented 4 years ago

🐛 Bug Report

Environment

Steps to reproduce

At first everything worked great. wrangler dev ran the code locally as expected. After the first time that I published using wrangler publish, suddenly wrangler dev stopped working. publish and build still works which is why I think it's not related to my code. The error that I get when I run wrangler dev is this:

✨  Built successfully, built project size is 356 KiB.
Error: EOF while parsing a value at line 1 column 0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! formdata-cloudflare@1.0.0 serve: `wrangler dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the formdata-cloudflare@1.0.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The verbose log file has this:

0 info it worked if it ends with ok
1 verbose cli [ '/Users/danbs/.nvm/versions/node/v11.10.1/bin/node',
1 verbose cli   '/Users/danbs/.nvm/versions/node/v11.10.1/bin/npm',
1 verbose cli   'run',
1 verbose cli   'serve' ]
2 info using npm@6.14.8
3 info using node@v11.10.1
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle formdata-cloudflare@1.0.0~preserve: formdata-cloudflare@1.0.0
6 info lifecycle formdata-cloudflare@1.0.0~serve: formdata-cloudflare@1.0.0
7 verbose lifecycle formdata-cloudflare@1.0.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle formdata-cloudflare@1.0.0~serve: PATH: /Users/danbs/.nvm/versions/node/v11.10.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/danbs/dev/dan/formdata-cloudflare/node_modules/.bin:/Users/danbs/Downloads/google-cloud-sdk/bin:/usr/local/opt/qt/bin:/Users/danbs/.nvm/versions/node/v11.10.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/laps:/opt/X11/bin:/Users/danbs/dev/dan/formdata-cloudflare/node_modules/.bin:/usr/local/Cellar/maven/3.5.0/libexec/bin
9 verbose lifecycle formdata-cloudflare@1.0.0~serve: CWD: /Users/danbs/dev/dan/formdata-cloudflare
10 silly lifecycle formdata-cloudflare@1.0.0~serve: Args: [ '-c', 'wrangler dev' ]
11 silly lifecycle formdata-cloudflare@1.0.0~serve: Returned: code: 1  signal: null
12 info lifecycle formdata-cloudflare@1.0.0~serve: Failed to exec serve script
13 verbose stack Error: formdata-cloudflare@1.0.0 serve: `wrangler dev`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/danbs/.nvm/versions/node/v11.10.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:197:13)
13 verbose stack     at ChildProcess.<anonymous> (/Users/danbs/.nvm/versions/node/v11.10.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:197:13)
13 verbose stack     at maybeClose (internal/child_process.js:984:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid formdata-cloudflare@1.0.0
15 verbose cwd /Users/danbs/dev/dan/formdata-cloudflare
16 verbose Darwin 18.7.0
17 verbose argv "/Users/danbs/.nvm/versions/node/v11.10.1/bin/node" "/Users/danbs/.nvm/versions/node/v11.10.1/bin/npm" "run" "serve"
18 verbose node v11.10.1
19 verbose npm  v6.14.8
20 error code ELIFECYCLE
21 error errno 1
22 error formdata-cloudflare@1.0.0 serve: `wrangler dev`
22 error Exit status 1
23 error Failed at the formdata-cloudflare@1.0.0 serve script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
danbars commented 4 years ago

EDIT: googling this error brings tons of results all related to Sentry. Is there a dependency on Sentry from wrangler?

danbars commented 4 years ago

Can anyone please look at this? I have 2 paying accounts and blocked from working!

solbloch commented 4 years ago

Same problem. One workaround, I've found, is using sudo for the wrangler dev as it seems to work if the account that wrangler is coming from isn't logged in. If you run sudo wrangler login or sudo wrangler config and login with root, as wrangler tells you to, it breaks.

nataliescottdavidson commented 4 years ago

@danbars, sorry you've been waiting on a response for this. I attempted to reproduce but haven't been able to track down the error yet. It may be an environment issue with npm. Have you tried clearing your cache and node_modules like so?

meoyawn commented 4 years ago

@nataliescottdavidson @solbloch @danbars just fixed this by commenting route and setting workers_dev=true in wrangler.toml

yacinehmito commented 3 years ago

I found that the bug originates from here: https://github.com/cloudflare/wrangler/blob/b1a9fa5d139c9341b84f12fa98523fe04742718e/src%2Fcommands%2Fdev%2Fedge%2Fsetup.rs#L164 (Tagging @EverlastingBugstopper as I see you in the git history)

I printed the URL and API token, then made a call from an HTTP client. Here are the response headers (probably useless info but you may never know):

date: Wed, 23 Dec 2020 10:33:09 GMT
content-length: 0
cf-ray: 60616c30298cf951-BRU
cf-cache-status: DYNAMIC
cf-request-id: 0730c1f2150000f951113c7000000001
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
x-envoy-upstream-service-time: 91
server: cloudflare

The body is empty.

I doubt this is a wrangler-related issue. It seems to be a problem with the backend.

By the way, I believe this to be a critical bug. I experienced it while strictly following the Getting Started guide of Cloudflare Workers, meaning that any new person testing the platform might experience it as well.

rib commented 3 years ago

Just trying to test my first 'hello world' worker and I'm hitting this issue currently.

I've just tried commenting out the route and zone_id in my wrangler.toml as suggested by @meoyawn but unfortunately that didn't work in my case.

node -v: v10.19.0 wrangler --version: wrangler 1.12.3 OS = Ubuntu 20.04.1 LTS

I used wrangler config to configure my access token

I've just done wrangler generate -t javascript test and then set my account_id in wrangler.toml

rib commented 3 years ago

Just for reference I tried some older versions of wrangler (back to 1.11.0) but they all just report: Error: EOF while parsing a value at line 1 column 0

rib commented 3 years ago

As suggested by @solbloch this issue seems related to the login since I don't see this issue if remove my default.toml with my authentication token. (Or at least it says Running preview without authentication and Listening on http://127.0.0.1:8787)

Is there going to be some subtle difference between using wrangler login vs wrangler config perhaps? It's awkward for me to test wrangler login instead on the machine I'm currently using.

rib commented 3 years ago

Ok, so actually I was able to try out using wrangler login and after it opened a browser window (Firefox) and I clicked to authorize it then it created a new token ok and said I could close the window. On the terminal though it was just stuck forever waiting for the new token :-/ (which sounds like this other issue: https://github.com/cloudflare/wrangler/issues/1514 which others are hitting so I don't really know why it's closed)

Based on some comments for that issue I tried out deleting the token I created manually and the new token created but even then wrangler login still just hangs forever waiting for the token.

This is really not an impressive out of box experience so far :-(

rib commented 3 years ago

Although probably unrelated to this I filed a separate issue for the fact that wrangler login hangs forever for me here: https://github.com/cloudflare/wrangler/issues/1703 since #1514 looks like it was originally for a different issue (even though there are a number of recent comments about seeing the same hang I see)

rib commented 3 years ago

In an effort to get a bit more detail with the error I ran with RUST_LOG=debug but didn't really get any more insight:

[2020-12-28T21:56:54Z INFO  wrangler::settings::global_config] No $WRANGLER_HOME detected, using $HOME
[2020-12-28T21:56:54Z INFO  wrangler] Starting dev server
[2020-12-28T21:56:54Z INFO  wrangler::settings::global_config] No $WRANGLER_HOME detected, using $HOME
[2020-12-28T21:56:54Z INFO  wrangler::settings::global_config] Using global config file: /home/rib/.wrangler/config/default.toml
[2020-12-28T21:56:54Z INFO  wrangler::settings::global_user] Config path exists. Reading from config file, /home/rib/.wrangler/config/default.toml
[2020-12-28T21:56:54Z DEBUG reqwest::connect] starting new connection: https://api.cloudflare.com/
[2020-12-28T21:56:54Z DEBUG hyper::client::connect::dns] resolving host="api.cloudflare.com"
[2020-12-28T21:56:54Z DEBUG hyper::client::connect::http] connecting to 104.19.192.29:443
[2020-12-28T21:56:54Z DEBUG hyper::client::connect::http] connecting to [2606:4700:300a::6813:c11d]:443
[2020-12-28T21:56:54Z DEBUG hyper::client::connect::http] connecting to [2606:4700:300a::6813:c01d]:443
[2020-12-28T21:56:56Z DEBUG hyper::client::connect::http] connected to 104.19.192.29:443
[2020-12-28T21:56:57Z DEBUG hyper::proto::h1::io] flushed 232 bytes
[2020-12-28T21:56:58Z DEBUG hyper::proto::h1::io] read 663 bytes
[2020-12-28T21:56:58Z DEBUG hyper::proto::h1::io] parsed 11 headers
[2020-12-28T21:56:58Z DEBUG hyper::proto::h1::conn] incoming body is empty
[2020-12-28T21:56:58Z DEBUG hyper::client::pool] pooling idle connection for ("https", api.cloudflare.com)
[2020-12-28T21:56:58Z DEBUG reqwest::async_impl::client] response '200 OK' for https://api.cloudflare.com/client/v4/accounts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/workers/subdomain/edge-preview
Error: EOF while parsing a value at line 1 column 0
rib commented 3 years ago

I also tried printing out the json being parsed (as found by @yacinehmito) and can at least confirm that I basically see the same thing - the response contents being parsed are empty....

URL=https://api.cloudflare.com/client/v4/accounts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/workers/subdomain/edge-preview
RESPONSE=Response {
url: Url { scheme: "https", host: Some(Domain("api.cloudflare.com")),
    port: None,
    path: "/client/v4/accounts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/workers/subdomain/edge-preview",
    query: None,
    fragment: None },
status: 200,
headers: {
    "date": "Mon, 28 Dec 2020 22:15:05 GMT",
    "content-length": "0",
    "connection": "keep-alive",
    "cf-ray": "608ea348feb0f42b-LHR",
    "cf-cache-status": "DYNAMIC",
    "cf-request-id": "074d04619f0000f42b3ca74000000001",
    "expect-ct": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
    "x-envoy-upstream-service-time": "61",
    "server": "cloudflare"
} }
TEXT=""
Error: EOF while parsing a value at line 1 column 0

Going to give up at this point for now I think :/ - as @yacinehmito suggests, it looks like a backend issue at this point or at least some kind of assumption about something that's maybe supposed to be configured on the backend but isn't?

rib commented 3 years ago

Aaaah, okeeey, my last hunch pointed me in the right direction, the issue for me was that I had to first explicitly navigate to "Workers" in the Cloudflare console and select Manage Workers to first create a workers.dev subdomain (which also requires agreeing to terms to use workers and selecting a usage tier).

It would of course be suuuuuper helpful if wrangler could print a really clear message in this situation which I imagine is going to be really common for a first time user who hasn't yet used Workers. From all the docs I'd seen none of them said to explicitly enable them via the console first!

hmmm, actually after a timeout now I'm hitting a different error...

I now get as far as Listening on http://127.0.0.1:8787 and it looks like it's working but then see:

thread 'tokio-runtime-worker' panicked at 'Failed to connect to devtools instance: Http(504)', src/commands/dev/socket.rs:29:14

:-/

rib commented 3 years ago

Looks like this is the next issue: https://github.com/cloudflare/wrangler/issues/1510 :-/

...yeah, I'd say I'm definitely getting concerned about whether this stuff is really sensible to consider using after hitting three separate wrangler issues back to back all related to trying out the most basic Hello World worker. :/

JamesBurgoon commented 3 years ago

I get this error as well just following the very basic Getting Started guide here: https://developers.cloudflare.com/workers/learning/getting-started

Wrangler: 1.12.3 NPM: 6.14.4 Node: 13.12.0

JamesBurgoon commented 3 years ago

I get this error as well just following the very basic Getting Started guide here: https://developers.cloudflare.com/workers/learning/getting-started

Wrangler: 1.12.3 NPM: 6.14.4 Node: 13.12.0

Update: I had to setup a Worker sub-domain on the CF admin site before wrangler dev or wrangler publish would work.

danbars commented 3 years ago

@nataliescottdavidson this is also happening for me again. Given all the activity on this ticket I think you should investigate.

Happens also with wrangler 1.12.3

Let me know if you need more info.

danbars commented 3 years ago

@rita3ko or anyone from cf team - can you assign someone to this ticket?

It is impossible to have a proper dev lifecycle with that issue. I can't locally test any code. Only option is to publish and hope for the best. This turns development into a long nightmare (code > publish > wait > refresh > test) and if it breaks rollback, etc, and of course it affects customers in production

@yacinehmito had suggested where the fault is https://github.com/cloudflare/wrangler/issues/1583#issuecomment-750112648

danbars commented 3 years ago

FYI - I opened a support ticket number 2084430

xortive commented 3 years ago

@rib thank you for your investigation, it's spot on. We identified a missing check for the existence of a chosen workers.dev subdomain, and once we return a proper error for that case we can update wrangler to provide a nicer error message here.

I believe this would manifest as a 500 with an "Internal Server Error" as the body, not a 200 with an empty body however, and I'd like to figure out how to reproduce the empty response body case.

@danbars I see in your original issue you were hitting this problem when using wrangler dev on a route, rather than with workers_dev = true.

I'm struggling to reproduce the exact empty response body that you are experiencing, and I want to make sure my test account is as close to your situation as possible.

danbars commented 3 years ago

Hi @xortive,

  1. All my workers are mapped to a route. While trying to troubleshoot this I tried to create a new non-mapped worker, and as far as I recall it still happened.
  2. Yes, this is consistent on every execution on all projects / workers that I have.

I never used wrangler subdomain. All my configurations were done manually. I'll try now again with a new worker and let you know.

danbars commented 3 years ago

@xortive , I just started a fresh worker and recorded step by step exactly what I did to reproduce. I also wrote the things that are seemingly unrelated. Hope this helps.

After the first 5 steps I can run wrangler dev. But then after completing the process, it fails with the error

  1. From CF dashboard create a new worker, save and deploy the default code. I also renamed it to test-wrangler
  2. In the IDE, create a new project, and run wrangler init
  3. Update the toml file with the name, accountid and route
  4. Run npm init to create a package.json file
  5. create index.js file
    addEventListener('fetch', (event) => {
      event.respondWith(new Response("HELLO"));
    });

    At this point wrangler dev works properly

  6. From the dashboard again > workers > Add route. Map the new worker to https://test.form-data.com/*
  7. Turn off the default workers.dev mapping
  8. Add 2 DNS records for test subdomain with IPs 151.101.1.195 and 151.101.65.195
  9. Update the local toml file with
    workers_dev = false
    route = "https://test.form-data.com/*"
    zone_id = "f6bxxxxxxxxxxxe15"
  10. Run wrangler publish
  11. Run wrangler dev

Now the error happens Error: EOF while parsing a value at line 1 column 0

I did try to run wrangler subdomain at this point, but it seems to only allow configuring workers.dev subdomain. Did I miss something?

xortive commented 3 years ago

@danbars is the apex A record for form-data.com configured to be proxied by cloudflare (orange cloud in the dash). If not, and if it's possible to turn that on, can you do that and see if this fixes your problem?

Currently, wrangler dev requires that the apex A record of your zone is proxied by cloudflare. We'll work on documenting this better, but unfortunately it's not something we can change in the short-term.

danbars commented 3 years ago

Hi @xortive,

The apex A record is not proxied by cloudflare. At the moment I can't change that because my website is hosted at Wix which doesn't work via this proxy. At the end of the month I'll be transferring the site to cf site-workers and then I'll be able to check it.

Question - if I keep something.workers.dev mapping for the worker in addition to my domain mapping, will this allow me to run it? It may be a reasonable workaround.

Anyway - good that you've identified the reason, and proper documentation will indeed save a lot of frustration to others.

xortive commented 3 years ago

Yeah, if you can adequately test your worker using the workers.dev mapping, that is a good work around for the time being.

On Tue, Mar 9, 2021 at 2:47 AM danbars notifications@github.com wrote:

Hi @xortive https://github.com/xortive,

The apex A record is not proxied by cloudflare. At the moment I can't change that because my website is hosted at Wix which doesn't work via this proxy. At the end of the month I'll be transferring the site to cf site-workers and then I'll be able to check it.

Question - if I keep something.workers.dev mapping for the worker in addition to my domain mapping, will this allow me to run it? It may be a reasonable workaround.

Anyway - good that you've identified the reason, and proper documentation will indeed save a lot of frustration to others.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cloudflare/wrangler/issues/1583#issuecomment-793496612, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEKLUMELEWU6HAIGSGNWYTTCXG7TANCNFSM4SEZYVIA .

-- Sincerely, Matthew Alonso

he/him/his - Workers Distributed Data - Systems Engineer

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity in the last 180 days. It will be closed if no further activity occurs in the next week. Please feel free to comment if you'd like it to remain open, and thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not had recent activity. You may re-open the issue if it is still relevant.