cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.58k stars 663 forks source link

๐Ÿ› BUG: "scheduled" template broken #4560

Closed Akiyamka closed 4 months ago

Akiyamka commented 9 months ago

Which Cloudflare product(s) does this pertain to?

Workers Runtime

What version(s) of the tool(s) are you using?

wrangler 3.19.0

What version of Node are you using?

v20.8.0

What operating system are you using?

Linux

Describe the Bug

Steps:

  1. pnpm create cloudflare@latest
  2. In which directory do you want to create your application? : ./daemon
  3. What type of application do you want to create? type Scheduled Worker (Cron Trigger)
  4. Do you want to use TypeScript?: Yes
  5. (skip deploy step)
  6. cd ./daemon
  7. npx wrangler dev
    [wrangler:inf] Ready on http://localhost:8787
    at __facade_modules_fetch__ (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:45:9)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at Object.next (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:50:11)
    at jsonError (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at __facade_invoke__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:63:9)
    at Object.fetch (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:114:11)

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

pnpm create cloudflare@latest
.../share/pnpm/store/v3/tmp/dlx-11402    | Progress: resolved 1, reused 0, dow
.../share/pnpm/store/v3/tmp/dlx-11402    |   +1 +
.../share/pnpm/store/v3/tmp/dlx-11402    | Progress: resolved 1, reused 0, dow
.../share/pnpm/store/v3/tmp/dlx-11402    | Progress: resolved 1, reused 0, dow
.../share/pnpm/store/v3/tmp/dlx-11402    | Progress: resolved 1, reused 0, dow
nloaded 1, added 1, done

using create-cloudflare version 2.8.1

โ•ญ Create an application with Cloudflare Step 1 of 3
โ”‚
โ”œ In which directory do you want to create your application?
โ”‚ dir ./daemon
โ”‚
โ”œ What type of application do you want to create?
โ”‚ type Scheduled Worker (Cron Trigger)
โ”‚
โ”œ Do you want to use TypeScript?
โ”‚ yes typescript
โ”‚
โ”œ Copying files from "scheduled" template
โ”‚
โ”œ Retrieving current workerd compatibility date
โ”‚ compatibility date 2023-11-21
โ”‚
โ•ฐ Application created

โ•ญ Installing dependencies Step 2 of 3
โ”‚
โ”œ Installing dependencies
โ”‚ installed via `pnpm install`
โ”‚
โ”œ Installing @cloudflare/workers-types
โ”‚ installed via pnpm
โ”‚
โ”œ Adding latest types to `tsconfig.json`
โ”‚ added @cloudflare/workers-types/2023-07-01
โ”‚
โ•ฐ Dependencies Installed

โ•ญ Deploy with Cloudflare Step 3 of 3
โ”‚
โ”œ Do you want to deploy your application?
โ”‚ yes deploy via `pnpm run deploy`
โ”‚
โ”œ Logging into Cloudflare checking authentication status
โ”‚ not logged in
โ”‚
โ”œ Logging into Cloudflare This will open a browser window
โ”‚ allowed via `wrangler login`
โ”‚
โ”œ Selecting Cloudflare account retrieving accounts
โ”‚ account user@gmail.com's Account
โ”‚
โ”œ Deploying your application
โ”‚
> daemon@0.0.0 deploy /home/user/git/_experements/ustatus/daemon
> wrangler deploy

 โ›… wrangler 3.19.0
-------------------
Total Upload: 0.45 KiB / gzip: 0.31 KiB
โ–ฒ [WARNING] You need to register a workers.dev subdomain before publishing to workers.dev

? Would you like to register a workers.dev subdomain now?
๐Ÿค– Using default value in non-interactive context: yes

โœ˜ [ERROR] This command cannot be run in a non-interactive context

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
๐Ÿชต  Logs were written to "/home/user/.config/.wrangler/logs/wrangler-2023-12-06_18-46-43_164.log"
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.

โ”‚
Error:
> daemon@0.0.0 deploy /home/user/git/_experements/ustatus/daemon
> wrangler deploy

 โ›… wrangler 3.19.0
-------------------
Total Upload: 0.45 KiB / gzip: 0.31 KiB
โ–ฒ [WARNING] You need to register a workers.dev subdomain before publishing to workers.dev

? Would you like to register a workers.dev subdomain now?
๐Ÿค– Using default value in non-interactive context: yes

โœ˜ [ERROR] This command cannot be run in a non-interactive context

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
๐Ÿชต  Logs were written to "/home/user/.config/.wrangler/logs/wrangler-2023-12-06_18-46-43_164.log"
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.

โ•ญโ”€ in ~/git/_experements/ustatus on mainโœ˜โœ˜โœ˜
โ•ฐโ”€ยฑ ls
daemon  devbox.json  devbox.lock  package.json
โ•ญโ”€ in ~/git/_experements/ustatus on mainโœ˜โœ˜โœ˜
โ•ฐโ”€ยฑ cd daemon
โ•ญโ”€ in ~/git/_experements/ustatus/daemon on mainโœ˜โœ˜โœ˜
โ•ฐโ”€ยฑ  npx wrangler dev
 โ›… wrangler 3.19.0
-------------------
โœ” Would you like to help improve Wrangler by sending usage metrics to Cloudflare? โ€ฆ yes
Your choice has been saved in the following file: ../../../../.config/.wrangler/metrics.json.

  You can override the user level setting for a project in `wrangler.toml`:

   - to disable sending metrics for a project: `send_metrics = false`
   - to enable sending metrics for a project: `send_metrics = true`
โŽ” Starting local server...
โ–ฒ [WARNING] Miniflare 3 does not support CRON triggers yet, ignoring...

[wrangler:inf] Ready on http://localhost:8787
[wrangler:err] Error: Handler does not export a fetch() function.
    at __facade_modules_fetch__ (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:45:9)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at Object.next (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:50:11)
    at jsonError (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at __facade_invoke__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:63:9)
    at Object.fetch (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:114:11)
[wrangler:inf] GET / 500 Internal Server Error (115ms)
[wrangler:err] Error: Handler does not export a fetch() function.
    at __facade_modules_fetch__ (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:45:9)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at Object.next (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:50:11)
    at jsonError (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
    at __facade_invokeChain__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:53:9)
    at __facade_invoke__ (/home/user/git/_experements/ustatus/daemon/node_modules/.pnpm/wrangler@3.19.0/node_modules/wrangler/templates/middleware/common.ts:63:9)
    at Object.fetch (/home/user/git/_experements/ustatus/daemon/.wrangler/tmp/bundle-JfDMqA/middleware-loader.entry.ts:114:11)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (17ms)
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit                                                                                                                                             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โŽ” Shutting down local server...
admah commented 9 months ago

@Akiyamka sorry you've had this issue. This appears to be a duplicate of #4263. In the meantime, you can either run wrangler deploy directly from the created folder or deploy it via the dashboard.

I wasn't able to replicate the fetch error that you have from the example code we provide.

I'm going to close this issue for now as a duplicate. Thanks!

Akiyamka commented 9 months ago

@admah , I'm afraid you closed this issue by mistake, my problem is not related to the "cannot be run in a non-interactive context" message (even though it is in the logs). If you look further and pay attention to the steps I mentioned, and look at the error message - you will notice that the problem is with the worker script template. As I managed to find out, a fetch hook must be present in the worker, which is absent in the example To put it simply - the template contains non-valid code, it lacks the export of fetch function

admah commented 9 months ago

@Akiyamka the template is not wrong here, other than the need for a JSON.stringify around one of the logged items. It is a valid scheduled Worker. The issue is related to some confusing error messaging that you're seeing. The browser has an automatic request for /favicon.ico that is not being handled properly by us in this instance and causing the error.

In the meantime, you can test your scheduled Worker via wrangler dev --test-scheduled and then run the scheduled event by visiting http://localhost:8787/__scheduled?cron=*+*+*+*+*. You should see the logs in your CLI, and the proper response from the URL.

wim-web commented 8 months ago

I have same issue

wim-web commented 8 months ago

In my environment, did not give me an error via curl, but via browser did

arthureberledev commented 6 months ago

i have the same issue on a fresh project initialized with npm create cloudflare@latest and selected cron job worker template (windows 11)

kaaaaaaaaaaai commented 6 months ago

same

jwcheon commented 4 months ago

same issue :(