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

    pxkq

    12/14/2021, 10:25 PM
    I'll open an issue
  • j

    jschlesser

    12/14/2021, 10:29 PM
    Interesting, the code in question is in node_modules/@cloudflare/pages_function_compiler/bin/plinko.mjs , in case you want to take a look. It has something to do with how its tree walking to create the route map. Its a doozy of a file though. It has a custom es6 parser in there. The readme of the node module sheds a bit of light.
  • p

    pxkq

    12/14/2021, 10:37 PM
    https://github.com/cloudflare/wrangler2/issues/110
    @Cloudflare#1437/pages_function_compiler
    isn't a public repository, but yeah, the problem is in
    plinko.worker.ts
  • e

    Erwin

    12/14/2021, 10:38 PM
    Hehe.. I am currently having the conversation about moving it into a public repository.. so might not be for too long.
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:38 PM
    Yup, that sounds like a bug. I recently touched that, so might have been my fault.
  • j

    jschlesser

    12/14/2021, 10:38 PM
    Im looking at it on my local node_modules directory
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:39 PM
    Think I might get it into the public repo tonight. (tomorrow at the latest)
  • e

    Erwin

    12/14/2021, 10:39 PM
    If you are able to look at it for more than a few minutes, you are a smarter man than I .. that is very much Glen and Greg code.. who are both a bit too brilliant for.. well, maybe not their own good, but certainly for my fragile ego 😉
  • p

    pxkq

    12/14/2021, 10:41 PM
    The `yield`s hurt my brain, so I won't try to understand it 😆
  • j

    jschlesser

    12/14/2021, 10:41 PM
    Heh, i have been staring at it for the better part of a couple of hours trying to solve a different problem. Ill take a peek to see if its obvious.
  • p

    pxkq

    12/14/2021, 10:43 PM
    Anyway thank you all for the quick responses, hopefully it'll be fixed soon, in the meantime I'll just move everything to the root
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:43 PM
    It’s gonna be L5256–5321-ish in bin/plinko.mjs I think.
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:43 PM
    But I’ll take a look at that as soon as I can
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:45 PM
    You should just be able to include stuff you've installed in node_modules. Is that not working for you?
  • j

    jschlesser

    12/14/2021, 10:47 PM
    I hadn't tried that 🤦‍♂️
  • j

    jschlesser

    12/14/2021, 10:50 PM
    Im trying to get Prisma backed by planetscale set up
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 10:59 PM
    If it's supported in Workers, it should just work, but functions being in beta, there might be a quirk or two to work out
  • g

    Greg Brimble | Cloudflare Pages

    12/14/2021, 11:00 PM
    Give us a shout if there's any issues 🙂
  • j

    jschlesser

    12/15/2021, 12:14 AM
    Unfortunately the Prisma module thinks it's being executed in a browser context. I'm 99% sure its because plinko is using the default esbuild target which is the browser (which is probably correct). I used esbuild to compile a very simple script that accesses my database that runs in node with
    node index.js
    and compiled it with
    npx esbuild --bundle index.js --outfile=index2.js
    and index.js works and index2.js barfs with the same error.
  • g

    Greg Brimble | Cloudflare Pages

    12/15/2021, 12:30 AM
    If you
    esbuild --platform=neutral
    , does that work?
  • j

    jschlesser

    12/15/2021, 12:32 AM
    esbuild complains
    node_modules/.prisma/client/index.js:57:21: error: Could not resolve "path" (use "--platform=node" when building for node)
  • j

    jschlesser

    12/15/2021, 1:56 AM
    As far as i can tell there is a bit of custom setup for Prisma and Workers. You can see the issue resolved here: https://github.com/prisma/prisma/issues/9894 And example project here that shows there are custom build shims, note the build section in wrangler.toml and build.js https://github.com/vinaypuppal/cfw-prisma-template
  • e

    Erwin

    12/15/2021, 2:04 AM
    The problem with that though at the moment is that Pages doesn't allow for custom build scripts.
  • j

    jschlesser

    12/15/2021, 2:10 AM
    yup, so follow me here on a crazy idea. I make a functionsprisma directory and i just do an npm init in there and add the prisma system and client and have a custom esbuild process that compiles the generated prismaclient and puts the output in my functions/lib directory so that I can import it using
    import {PrismaClient} from '/lib/prismaclient'
    Or something to that effect. Does that seem like a generic way to include external libraries that can play well with workers if they are compiled and shimmed correctly?
  • j

    jschlesser

    12/15/2021, 2:12 AM
    I should have said, pages functions, not workers
  • e

    Erwin

    12/15/2021, 2:13 AM
    Yup.. that should absolutely work
  • e

    Erwin

    12/15/2021, 2:14 AM
    Great idea.. Something that we would love to not have necessary, but until that time it is fine 🙂
  • s

    Subh

    12/15/2021, 4:27 AM
    env is not defined 😦
  • s

    Subh

    12/15/2021, 4:29 AM
    Docs says it would just work like https://developers.cloudflare.com/workers/platform/environment-variables
  • b

    Beny

    12/15/2021, 8:06 AM
    What are the cpu & fetch limits for pages functions?
1...434445...392Latest