https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • c

    Cоlе

    11/18/2021, 11:06 PM
    I think it should be this guy here https://pvp-legacy-api.pages.dev/
  • w

    Walshy | Pages

    11/18/2021, 11:07 PM
    ty
  • w

    Walshy | Pages

    11/18/2021, 11:09 PM
    Could you try to rename your functions folder to like
    functions-disabled
    and push? Wondering if it is the function maybe causing this failure
  • w

    Walshy | Pages

    11/18/2021, 11:09 PM
    It shouldn't be... but worth a shot
  • c

    Cоlе

    11/18/2021, 11:09 PM
    I'll give it a shot
  • i

    Isaac McFadyen | YYZ01

    11/18/2021, 11:13 PM
    Not really sure... if it helps, I had to rename my functions folder to _functions because it was causing issues originally.
  • c

    Cоlе

    11/18/2021, 11:13 PM
    @User it did deploy
  • w

    Walshy | Pages

    11/18/2021, 11:13 PM
    Right so it seems it was the function..
  • w

    Walshy | Pages

    11/18/2021, 11:13 PM
    hmm
  • c

    Cоlе

    11/18/2021, 11:13 PM
    I'm gonna rename it back and try, just as a sanity check
  • c

    Cоlе

    11/18/2021, 11:34 PM
    ._. I think I fixed it
  • c

    Cоlе

    11/18/2021, 11:34 PM
    I'm gonna see if I can undo it and break it again
  • c

    Cоlе

    11/18/2021, 11:43 PM
    nope, no idea
  • c

    Cоlе

    11/18/2021, 11:43 PM
    very cool
  • p

    PatrickJ

    11/19/2021, 9:52 AM
    I'm playing with pages advanced mode (so _worker.js file basically) and javascript modules. However it doesn't seem to be working after I try to import module. Am i doing something wrong?
    Copy code
    // _worker.js
    import { add } from "./add";
    
    export default {
      async fetch(request, environment, context) {
        if (request.url.includes("/api/")) {
          console.log("worker", request.url);
    
          const count = add(2, 3);
    
          return new Response(count);
        }
        console.log("static", request.url);
    
        return env.ASSETS.fetch(request);
      },
    };
    
    
    // add.js
    export function add(a, b) {
      return a + b;
    }
  • p

    PatrickJ

    11/19/2021, 9:53 AM
    Error:
    Copy code
    VMScriptRunnerError [ERR_MODULE_RULE]: Unable to resolve "_worker.js" dependency "./add": no matching module rules
        at ModuleLinker.linker (file:///opt/homebrew/lib/node_modules/wrangler/node_modules/@miniflare/runner-vm/dist/src/index.js:59:13)
        at ModuleWrap.<anonymous> (node:internal/vm/module:312:30)
        at SourceTextModule.<computed> (node:internal/vm/module:311:36)
        at SourceTextModule.link (node:internal/vm/module:197:22)
        at VMScriptRunner.runAsModule (file:///opt/homebrew/lib/node_modules/wrangler/node_modules/@miniflare/runner-vm/dist/src/index.js:220:18)
        at VMScriptRunner.run (file:///opt/homebrew/lib/node_modules/wrangler/node_modules/@miniflare/runner-vm/dist/src/index.js:242:28)
        at EventTarget.#reload (file:///opt/homebrew/lib/node_modules/wrangler/node_modules/@miniflare/core/dist/src/index.js:1797:42) {
      code: 'ERR_MODULE_RULE',
      cause: undefined
    }
  • g

    Greg Brimble | Cloudflare Pages

    11/19/2021, 9:53 AM
    Single Worker scripts only support a single compiled file at the moment, so you'll need to bundle that yourself.
  • g

    geelen

    11/19/2021, 9:53 AM
    Yup, I recommend esbuild
  • p

    PatrickJ

    11/19/2021, 9:54 AM
    Gotcha, I think I missed that
  • g

    Greg Brimble | Cloudflare Pages

    11/19/2021, 9:54 AM
    esbuild src/index.ts --bundle --outfile=dist/_worker.js --format=esm --minify
  • g

    geelen

    11/19/2021, 9:55 AM
    you have an extra
    --bundle
  • g

    Greg Brimble | Cloudflare Pages

    11/19/2021, 9:55 AM
    (Assuming build directory is
    dist
    and you have
    index.ts
    and
    app.ts
    in
    src
    )
  • p

    PatrickJ

    11/19/2021, 9:58 AM
    Works! Thanks guys
  • p

    PatrickJ

    11/19/2021, 10:04 AM
    Do you have any ETA for workers logging in Pages?
  • g

    geelen

    11/19/2021, 10:07 AM
    sadly no, it's actually... a lot harder than you might think so there's a few other things we'll do first
  • g

    geelen

    11/19/2021, 10:07 AM
    https://developers.cloudflare.com/pages/platform/functions#adding-middleware
  • g

    geelen

    11/19/2021, 10:08 AM
    i recommend adding at least the error handling middleware here
  • g

    Greg Brimble | Cloudflare Pages

    11/19/2021, 10:09 AM
    Yup. I made one with Toucan (https://github.com/robertcepa/toucan-js) yesterday to pass to Sentry. Took about 10 minutes to set up.
  • p

    PatrickJ

    11/19/2021, 10:09 AM
    I'm planning on using just "_worker" file for now, so not sure if middleware is an option. I've seen that Toucan thing as well and it looks interesting.
  • p

    PatrickJ

    11/19/2021, 10:11 AM
    This is because I'd like to make React SSR app, and functions are mapped to it's path.
12345...392Latest