Skip to content

🐛 BUG: cannot publish simple worker & horrible error message #3097

Description

@dotysan

Which Cloudflare product(s) does this pertain to?

Wrangler

What version of Wrangler are you using?

2.16.0

What operating system are you using?

linux

Describe the Bug

This works:

import {Router} from 'itty-router';
const noContent = new Response(null, {status: 204});
const RTR= Router();
RTR
  .get('/', ()=> {return new Response('/')})
  .get('/favicon.ico', ()=> noContent)
  .all('*', ()=> new Response('404, not here!', {status: 404}))
;

But as soon as I try and define a 2nd Response() const...

import {Router} from 'itty-router';
const noContent = new Response(null, {status: 204});
const notHere = new Response('404, not here!', {status: 404});
const RTR= Router();
RTR
  .get('/', ()=> {return new Response('/')})
  .get('/favicon.ico', ()=> noContent)
  .all('*', ()=> notHere)
;

...then wrangler publish generates this horrible error message:

✘ [ERROR] A request to the Cloudflare API (/accounts/{account_identifier}/workers/scripts/{script_name}) failed.

  Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random
  values, can only be performed while handling a request.
    at index.js:26:15
   [code: 10021]

It appears that simply defining two const foo = new Response() trips up the POST to the undocumented accounts/{account_identifier}/workers/scripts/{script_name}/edge-preview API.

The example above works perfectly if I do wrangler dev --local. (However wrangler dev also fails, why?)

Even if a) I'm doing something wrong, or b) it's actually a bug in itty-router, please fix the horrible error message! I can't even find where that index.js:26:15 lives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions