cloudflare / worker-typescript-template

ʕ •́؈•̀) TypeScript template for Cloudflare Workers
Apache License 2.0
431 stars 95 forks source link

Cannot run this template (Error on remote worker) #75

Open simplenotezy opened 1 year ago

simplenotezy commented 1 year ago

Running this command sequence (using wrangler:

npx wrangler generate worker-playground https://github.com/cloudflare/worker-typescript-template
cd worker-playground
npm install
npm run dev # or npx wrangler dev src/index.ts

Results in the following error:


❯ npx wrangler dev src/index.ts
 ⛅️ wrangler 2.0.24 (update available 2.6.2)
------------------------------------------------------
▲ [WARNING] The entrypoint src/index.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using "service-worker" format...

Retrieving cached values for userId from node_modules/.cache/wrangler
⬣ Listening at http://localhost:8787
Total Upload: 0.21 KiB / gzip: 0.18 KiB
✘ [ERROR] Error on remote worker: ParseError: A request to the Cloudflare API (/accounts/XXXX/workers/scripts/worker-typescript-template/edge-preview) failed.

      at throwFetchError
  (/Users/mf/Projects/worker-playground/node_modules/wrangler/wrangler-dist/cli.js:136497:17)
      at fetchResult
  (/Users/mf/Projects/worker-playground/node_modules/wrangler/wrangler-dist/cli.js:136466:5)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async createPreviewToken
  (/Users/mf/Projects/worker-playground/node_modules/wrangler/wrangler-dist/cli.js:136758:29)
      at async createWorkerPreview
  (/Users/mf/Projects/worker-playground/node_modules/wrangler/wrangler-dist/cli.js:136778:17)
      at async start
  (/Users/mf/Projects/worker-playground/node_modules/wrangler/wrangler-dist/cli.js:137471:34) {
    text: 'A request to the Cloudflare API
  (/accounts/XXXX/workers/scripts/worker-typescript-template/edge-preview)
  failed.',
    notes: [
      {
        text: 'No event handlers were registered. This script does nothing.\n' +
          ' [code: 10021]'
      }
    ],
    location: undefined,
    kind: 'error',
    code: 10021
  }
klausbreyer commented 1 year ago

I also had this error when I tried it half a year ago. I have now created a PR with what fixed it for me. (But I also bumped the dependencies) https://github.com/cloudflare/worker-typescript-template/pull/76

simplenotezy commented 1 year ago

Nice, thanks!