https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-help
  • Inconsistent Bundled Requests Count
    k

    Kynson

    05/27/2023, 3:20 AM
    I notice that the bundled request count on the dashboard keeps fluctuating (I keep refreshing the page) and I wonder if this is normal? Tested on both Safari and Chrome

    https://cdn.discordapp.com/attachments/1111856479503400960/1111856479893467258/Screen_Recording_2023-05-27_at_11.05.15.mov▾

  • How to setup Miniflare + Typescript + Vitest (Durable Object)?
    r

    rattlesnake

    05/28/2023, 12:52 AM
    I've been trying to setup my project for tests, but I keep getting this error whenever I run my tests: > Class "Test" for Durable Object "TEST" not found Does anyone have an example project that I can refer to? Many thanks. Packages:
    Copy code
    "typescript": "^5.0.4" 
    "esbuild": "^0.17.19"
    "miniflare": "^3.0.1"
    "vitest": "^0.31.1"
    "vitest-environment-miniflare": "^2.14.0"
    "wrangler": "^2.20.0"
    Scripts:
    Copy code
    "test": "npm run build && NODE_OPTIONS=--experimental-vm-modules vitest"
    "build": "esbuild --bundle --sourcemap --outdir=dist ./src/index.js"
    In package.json:
    "main": "./dist/index.js"
    vitest.config.ts:
    Copy code
    import { defineConfig } from "vitest/config";
    export default defineConfig({
      test: {
        environment: "miniflare",
        environmentOptions: {
          modules: true,
          scriptPath: "./dist/index.js",
          durableObjects: {
            TEST: "Test",
          },
          bindings: { TEST: "Test" },
        },
      },
    });
    Error:
    Copy code
    Error: Class "Test" for Durable Object "TEST" not found
    ❯ DurableObjectsPlugin.reload node_modules/@miniflare/shared-test-environment/node_modules/@miniflare/durable-objects/src/plugin.ts:352:15
     ❯ MiniflareCore.#runAllReloads node_modules/@miniflare/shared-test-environment/node_modules/@miniflare/core/src/index.ts:705:24
     ❯ MiniflareCore.#reload node_modules/@miniflare/shared-test-environment/node_modules/@miniflare/core/src/index.ts:861:13
     ❯ MiniflareCore.getGlobalScope node_modules/@miniflare/shared-test-environment/node_modules/@miniflare/core/src/index.ts:1041:5
     ❯ Proxy.createMiniflareEnvironment node_modules/@miniflare/shared-test-environment/src/index.ts:79:25
     ❯ Object.setup node_modules/vitest-environment-miniflare/src/index.ts:79:33
     ❯ withEnv node_modules/vitest/dist/entry.js:182:15
     ❯ run node_modules/vitest/dist/entry.js:268:3
     ❯ run node_modules/vitest/dist/worker.js:69:5
     ❯ node_modules/tinypool/dist/esm/worker.js:109:20
  • Attempting to delete worker throws Code 10064, despite having no queues.
    i

    Iscah

    05/28/2023, 2:33 AM
    Good evening! I'm genuinely at a loss for what I'm doing here, and it's making me furious. I can't delete a worker because: >
    Copy code
    script still in use as a consumer for a queue (Code: 10064)
    And there's seemingly no queue in place. Getting furious, though that doesn't help anything.
  • Cloudflare Workers Admin users can see Audit Log also.
    k

    kazu0617

    05/28/2023, 6:40 AM
    Hello. I’m trying to invite account for some other users, but how to set invite as editing for Workers Only? I set
    Cloudflare Workers Admin
    as new account, but it can check audit log also.
  • lots of my deployed workers just got multiple requests at the same time
    p

    PencilNavigator

    05/28/2023, 9:18 AM
    There was two deployed service i deleted but got the same issue too (forgot to take screenshot). Those service aren't even tied with a domain and was deployed 24hrs ago.

    https://cdn.discordapp.com/attachments/1112308871327907922/1112308871537643630/b81205578d68fef7.png▾

    https://cdn.discordapp.com/attachments/1112308871327907922/1112308871931895888/0d1b3495115002c3.png▾

    https://cdn.discordapp.com/attachments/1112308871327907922/1112308873190199356/321689177dbc9ade.png▾

    e
    c
    • 3
    • 11
  • Migrating to modules problems
    s

    srnyx

    05/28/2023, 4:45 PM
    I'm trying to migrate to modules, however it's still using my old event listener for some reason (even though I removed it). `src/worker.js`: (doesn't work)
    Copy code
    js
    export default {
      fetch(request) {
        return new Response("Hello, World!");
      }
    }
    I tried including a
    wrangler.toml
    file too but that also didn't work:
    Copy code
    toml
    name = "srnyx-com"
    main = "src/worker.js"
    • 1
    • 4
  • Please help. I am trying to import a typescript module in a worker in the same git repo.
    s

    somoni

    05/28/2023, 10:58 PM
    https://github.com/ymolists/sbox-cflare/blob/main/server/package.json#L10 this 👆 is how i am trying to import this typescript module in the same git repo. Can anyone please tell me what i am doing droing ? Here is the error i get when i try to run
    wrangler dev
    Copy code
    ✘ [ERROR] Could not resolve "shared"
    
        src/worker.ts:11:22:
          11 │ import {Greet01} from "shared"
             ╵                       ~~~~~~~~
    
      You can mark the path "shared" as external to exclude it from the bundle, which will remove this error.
    
    
    ✘ [ERROR] Build failed with 1 error:
    
      src/worker.ts:11:22: ERROR: Could not resolve "shared"
    k
    • 2
    • 3
  • waitUntil illigal invocation
    o

    o0th

    07/19/2023, 6:58 AM
    I was planning to use waitUntil, but as soon it runs the worker die with this error:
    Copy code
    [mf:err] TypeError: Illegal invocation
        at Object.fetch (/path/src/index.js:59:5)
        at __facade_modules_fetch__ (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:46:16)
        at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
        at Object.next (/path/node_modules/wrangler/templates/middleware/common.ts:50:11)
        at jsonError (/path/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
        at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
        at __facade_invoke__ (/path/node_modules/wrangler/templates/middleware/common.ts:63:9)
        at Object.fetch (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:114:11)
    wrangler version 3.2.0 and 3.3.0. In this example I'm just running a resolve, running anything else the promise will run but the worker will die anyway
    Copy code
    js
    export default {
      fetch: async (request, env, { waitUntil }) => {
        waitUntil(Promise.resolve())
        return new Response('hello')
      }
    }
    am I doing something wrong?
    s
    s
    • 3
    • 4
  • Promise will never complete error for WASI worker
    z

    zeroblackalpha

    07/28/2023, 6:10 AM
    I'm writing a WASI worker using
    @cloudflare/workers-wasi
    and while it works locally using wrangler, I get a
    Promise will never complete.
    error when actually deploying to cloudflare workers. I am using Wrangler 3.4.0 and Rust 1.71.0. I am building the WASI image using cargo-wasi in release mode, so wasm-opt is enabled. worker.ts
    Copy code
    import { WASI } from '@cloudflare/workers-wasi';
    import demoWasm from '../../../target/wasm32-wasi/release/wasi_test.wasm';
    export default {
        async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
            const stdout = new TransformStream();
            const wasi = new WASI({
                stdout: stdout.writable
            });
            const instance = new WebAssembly.Instance(demoWasm, {
                wasi_snapshot_preview1: wasi.wasiImport
            });
            ctx.waitUntil(wasi.start(instance));
            return new Response(stdout.readable);
        }
    };
    main.rs
    Copy code
    use image;
    
    fn main() {
        let image_bytes = include_bytes!("foster-lake.jpg");
        let mut img = image::load_from_memory(image_bytes).expect("Failed to parse image");
        let height = img.height();
        println!("{height}");
    }
    The code seems to fail specifically on
    image::load_from_memory(image_bytes)
    . The
    include_bytes
    does work as the worker runtime correctly returns the image if I try to directly print out the bytes of the image to stdout. I don't expect to have hit any aborts or panics as the image is being loaded correctly and it decodes correctly locally. Are there known behavior differences between wrangler and the worker runtime for WASI?
    d
    • 2
    • 1
  • console.log(request) doesn't show shape of request
    b

    bonsaye

    07/29/2023, 3:25 PM
    Hey everyone, I have a local environment running,
    wrangler dev
    In my worker script, I have
    console.log(request)
    and in the terminal all I see is
    Copy code
    Request {
    
    }
    k
    u
    • 3
    • 16
  • How to deploy worker?
    o

    originalauthority

    09/06/2023, 8:48 PM
    I'm probably being a bit stupid here, but I'm really new to Workers, having been using page rules before (looking for a bit more flexibility on cookie bypass etc, and don't want to shell out for enterprise/business). I have a Worker script (pastebin for anyone interested: https://pastebin.com/5kUGaL2S) that I think does what I need (bypass on certain cookies etc), and I've tried to set it up, but I'm having a bit of difficulty getting it to actually work. Basically, I have a domain (domain.com, redacted in the script) and several subdomains (.domain.com, wildcard), and I need the worker to be the one to intercept the request and then pass it to the server if it can't be served from the cache. I've done the following: - saved and deployed - added a route for domain.com with the zone domain.com - added a route for *.domain.com with the zone domain.com, but it doesn't seem to be actually working (I can tell because my worker should be logging the start time to the console), am I being really stupid, or? Does anyone know what I'm doing wrong? Oddly enough, I can see 1.2k requests when I look at the worker?
    c
    • 2
    • 8
  • Email Routing reports that email messages are dropped.
    c

    cfored

    11/22/2023, 2:13 AM
    Hi, The Cloudflare Email Workers, catch-all address, Activity Log of the Email Routing reports that email messages are dropped. However, the workers-n8n-3 logs shows pass: { "outcome": "ok", "scriptName": "workers-n8n-3", "diagnosticsChannelEvents": [], "exceptions": [], "logs": [], "eventTimestamp": 1700617847566, "event": { "rawSize": 69420, "rcptTo": "director@xxxx.com", "mailFrom": "lacounty@xxxx.gov" }, "id": 1 } See the screenshot images for details: Why are my email messages not routed through the Cloudflare workers (workers-n8n-3)? Regards, Hal
    c
    g
    • 3
    • 6
  • sending attachment from email worker
    k

    kittens-on-datura

    12/02/2023, 6:13 PM
    I'm building a contact form where people can attach files and they will be emailed to me, and while I can attach files, they are not decoded from the base64 form they're sent in. Does anyone know how can I change the content transfer encoding? I can't just send the raw file either, some characters seem to get lost (or I'm not converting the uint8array to a string properly, which might be causing the issue)
    • 1
    • 6
  • Where can I get a list of all predefined models?
    t

    thejedi3504

    12/05/2023, 12:54 PM
    I'm trying to use Workers-AI, and I was able to use llama2. There is a list in the docs that includes some other 5 or so models. Where can I get a full list of all available models?
    h
    e
    t
    • 4
    • 13
  • Cannot test locally after wrangler 3.17 - get ECONNREFUSED
    j

    Jacob Wright

    12/13/2023, 5:38 PM
    Using https://github.com/jahands/do-demo I am able to get tests passing up to Wrangler 3.17. Starting with 3.18 (to 3.20) I get this error when running
    unstable_dev(...)
    before the
    beforeAll()
    is finished executing. This is the same for my own projects. > TypeError: fetch failed > ❯ fetch node_modules/wrangler/wrangler-dist/cli.js:16838:17 > ❯ processTicksAndRejections node:internal/process/task_queues:95:5 > ❯ Object.fetch node_modules/wrangler/wrangler-dist/cli.js:151422:16 > > Caused by: Error: connect ECONNREFUSED ::1:52557 > ❯ connect ECONNREFUSED ::1:52557 > ❯ TCPConnectWrap.afterConnect [as oncomplete] node:net:1495:16 Where/how should I report this?
    a
    i
    • 3
    • 4
  • Simple image manipulation (darken) that works on workers
    a

    ajgeiss0702

    12/13/2023, 5:52 PM
    Hello, I need to darken an image before running it through OCR, however I have not found a way to do this on workers. I was messing with it locally using the
    sharp
    package, however I realized this package is not compatable with workers. I'm wanting to put it in an existing cron worker that puts the data into KV after. I already have it putting other data related to the image, so it makes sense to do it there too. I'm planning on just using google's OCR api since it seems to be the best. Is there a similar one that does? The only thing I need to do is to darken the image so that OCR doesnt pick up on random details that I dont need (I just want it to read the big white text in the image) Thank you in advance
    i
    • 2
    • 4
  • Thinking Outside The Box With Durable Objects
    d

    danboyle8637

    12/13/2023, 8:56 PM
    I'm not building this yet... but just thinking about an interesting way to use Durable Objects and alarms. What do you think of using alarms to allow users to set up alarms to message the app's service worker to kick off a push notification? Besides the alarm the DO will save the custom message the user wants sent back to them. I am just thinking about ways to schedule push notifications since this is a new topic for me.
    m
    r
    • 3
    • 3
  • Using Worker for creating zip on-the-fly
    a

    Artyum

    12/16/2023, 12:28 PM
    I'm having hard time understanding if Worker is the right choice for my use-case. I currently have some files stored in R2 and I would like to allow my users to download them as a single file (.zip), thus creating the zip on-the-fly. But after reading the pricing page, I don't understand if it fits my use-case. I see something like: > Max of 30 seconds of CPU time per invocation Depending on the size of the files and the download speed of my user, the download might last more than 30 seconds or even 30 minutes, I can't tell.
    t
    • 2
    • 1
  • Delay ctx.waitUntil() until fetch() has completed or canceled
    j

    justinlesko

    12/16/2023, 4:33 PM
    Hi! I'm wondering if anyone has a method for delaying the execution of the promise passed into
    ctx.waitUntil()
    until the primary
    fetch()
    has completed or canceled?
    h
    d
    • 3
    • 8
  • Could not resolve "@cloudflare/pages-plugin-mailchannels"
    s

    ssokolow

    12/16/2023, 8:47 PM
    I'm trying to set up a contact form for a simple Pages site but the instructions on https://blog.cloudflare.com/sending-email-from-workers-with-mailchannels/ just result in a
    Could not resolve "@cloudflare/pages-plugin-mailchannels"
    error when I make a new push. npmjs.com seems to indicate that
    @cloudflare/pages-plugin-mailchannels
    still exists and has over 1,000 weekly downloads, which suggests it hasn't been renamed, but I have no experience with Cloudflare Workers and I find the distinction between using Workers and using Pages Functions hazy and confusing, so I don't know how to go about testing the "must be manually added as a dependency first" hypothesis with Git-based deploy (the docs just talk about Wrangler) and it being located in
    functions/_middleware.ts
    .
    k
    • 2
    • 7
  • email worker webhook not working
    g

    gutenight

    12/17/2023, 2:46 AM
    I am currently trying to relay emails sent to a worker to my webhook. it works fine when i send a test on the cloudflare site but when a real email is sent it doesnt send anything to my webhook. in the overview tab it shows that the email was received (although it says it was dropped ive read in other threads that that's just a default response) nothing is sent to the webhook. I am in control of the server and have put as many things as i can think of to log or find out what the issue is but ive come to the conclusion that it just isnt sending the request. anyone have any idea how to fix it?
    c
    • 2
    • 98
  • Caching literally not working
    s

    Silabear

    12/17/2023, 7:46 PM
    I'm trying to create a file script which caches all files for 30 seconds. However, it never caches it, or at least it never gets it from the cache. Every time it's a cache miss. I've been trying to fix this for a while now and have gotten nowhere. Can someone have a look to see if the issue is obvious? https://sourceb.in/HZVNZhS2eo
    k
    • 2
    • 6
  • cron job success but no database changes
    a

    Arnø

    12/18/2023, 5:33 AM
    Hello, I’ve setup a cron job to import datas in my D1 database. I’ve triggered the cron in local and it’s working fine. I’ve also create a route to test my cron manually online and it’s also works fine. But, when my cron is executed, my database not changes. I think the code is not executed or there is an error, but the Dashboard said it’s a success. How can I debug this ?
    u
    • 2
    • 3
  • Why is cf-cache always DYNAMIC
    p

    prodigy_anthill

    12/18/2023, 7:18 AM
    Could someone please help me understand an issue ? Cross posted here: https://community.cloudflare.com/t/why-is-the-requested-resource-not-cahced/592894 Thank you
    u
    • 2
    • 8
  • Email worker inside of a pages repo?
    x

    xeon06

    12/18/2023, 4:32 PM
    Hey folks, I'm trying to develop something that uses both pages for deployment of a frontend / backend website, but also an email worker. I want to try to keep the code in the same repo, but I realize that it will need to be separate deployments on CloudFlare, since pages doesn't support email routing. Are there existing patterns to keep both my pages and my email worker's code in the same repo while still being able to deploy everything?
    e
    • 2
    • 4
  • next-on-pages build gives "Internal Server Error" on yarn pages:dev
    t

    thecachier_17015

    12/18/2023, 9:40 PM
    Hi! We have a NextJS app and trying to deploy to Cloudflare. On the yarn pages:build step, the following warnings/messages are displayed: % yarn pages:build yarn run v1.22.1 $ npx @cloudflare/next-on-pages ⚡️ @cloudflare/next-on-pages CLI v.1.8.2 ⚡️ Detected Package Manager: yarn (1.22.1) ⚡️ Preparing project... ⚡️ Project is ready ⚡️ Building project... ▲ Vercel CLI 32.7.2 .. ▲ Detected Next.js version: 14.0.4 .. .. [webpack.cache.PackFileCacheStrategy] Serializing big strings (109kiB) impacts deserialization performance (consider using Buffer instead and decode when needed) .. [webpack.cache.PackFileCacheStrategy] Serializing big strings (112kiB) impacts deserialization performance (consider using Buffer instead and decode when needed) ▲ ⚠ Compiled with warnings ./node_modules/scheduler/cjs/scheduler.production.min.js ▲ A Node.js API is used (MessageChannel at line: 120) which is not supported in the Edge Runtime. .. ./node_modules/scheduler/cjs/scheduler.production.min.js ▲ A Node.js API is used (setImmediate at line: 51) which is not supported in the Edge Runtime. The build completes successfully. The dependency of Scheduler looks like this: $ npm ls scheduler └─┬ react-dom@18.2.0 └── scheduler@0.23.0 So this is an npm module used by standard react-dom. Running with yarn pages:dev and launching localhost shows this only message in the browser: Internal Server Error And on the command-line this can be seen: ✘ [ERROR] ⨯ TypeError: (w.adapter || b.adapter) is not a function wrangler:inf] GET / 500 Internal Server Error (178ms) Not much to go on. There are references to generated files, like: .../.vercel/output/static/_worker.js/__next-on-pages-dist__/webpack/86d03c243df5247d6f6729bd979a6117.js:62:138483) But we assume this is related to the warnings/messages seen while building the application. Has anyone seen something similar? We appreciate hint and tips, as there seem to be little information available. Kind regards, /Peter
    b
    • 2
    • 3
  • Is there a way to use `pg` in a Next.js project setup with `@cloudflare/next-on-pages?
    j

    JanPrisma

    12/19/2023, 2:50 AM
    I have project that is setup following https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/, and now I tried to use
    pg
    to connect to a remote database. As soon as I import and use
    pg
    in one of my funtions though, I get errors like this during `npm run build`:
    Copy code
    $ npm run build
    
    > next-pg@0.1.0 build
    > next build
    
       ▲ Next.js 14.0.4
    
    Failed to compile.
    
    ./node_modules/pg-connection-string/index.js:76:69
    Module not found: Can't resolve 'fs'
    
    https://nextjs.org/docs/messages/module-not-found
    
    Import trace for requested module:
    ./node_modules/pg/lib/connection-parameters.js
    ./node_modules/pg/lib/client.js
    ./node_modules/pg/lib/index.js
    ./app/api/pg/route.js
    ...
    How can I use
    pg
    in a Next.js project that I want to deploy to Cloudflare Pages?
    m
    c
    d
    • 4
    • 17
  • Request to URL on the same zone but in CNAME configuration
    p

    plopix

    12/19/2023, 6:22 AM
    Hello, I have a weird behavior that I have an hard time debugging. I reach out my worker via my custom domain, this worker is actually doing a fetch to another endpoint on a different domain but same zone. like Worker is: xxxx.plop.com and I fetch from this worker to yyyy.plop.com And when I do that the fetch is clearly not working all the time.. like a weird resolving issue. If I access the worker from the route "worker.dev" it's working 100% i have plenty of debug the fetch is just empty OR sometime it says: "Invalid Link" Any hint ? or way to debug more? Thanks
    k
    • 2
    • 8
  • Store a JWT to be pulled from a worker
    c

    com.bo

    12/19/2023, 9:43 AM
    I'm need a worker to attach a JWT in the headers of a call to a 3rd party API. This JWT should be refreshed every ~30min. My plan was to have a chron job triggering a worker to generate a new JWT. But i'm unsure of where i should store that JWT so that my other worker making the API calls can retrieve it. Secrets cannot be set by worker
    h
    • 2
    • 2
  • Simple Worker 403 fetching https://api.github.com/graphql
    m

    michael65610

    12/19/2023, 3:43 PM
    I've double and triple checked tokens, access, etc and verified working with Postman and Node Scripts that mimic the worker. Unfortunately, I still get 403's both locally in a wrangler env and in the production env. Error: API responded with status 403 at Object.fetch (file:///Users/miz/Dev/githubprojects-everhour-reporting/worker-githubprojectsreport/src/index.js:23:17) at async jsonError (file:///Users/miz/Dev/githubprojects-everhour-reporting/worker-githubprojectsreport/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10)
    c
    • 2
    • 2
1...678910Latest