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

    thm76

    11/23/2021, 7:27 AM
    I'm just playing with Pages functions, and getting this error: Compiling worker to "/opt/pages/functions/user-worker.js" > ../../buildhome/repo/node_modules/handlebars/lib/index.js:17:19: error: Could not resolve "fs" (use "platform: 'node'" when building for node) 17 │ var fs = require('fs'); ╵ ~~~~ That "platform" setting sounds like it's for esbuild? Is there a way to set this?
  • t

    thm76

    11/23/2021, 7:38 AM
    I might look into bundling my function using esbuild during my build phase...
  • e

    Erwin

    11/23/2021, 8:05 AM
    Workers don’t support NodeJS, but only JavaScript (+assorted extra libraries). So you can import things like fs.
  • g

    geelen

    11/23/2021, 9:01 AM
    ^ Erwin means you can't import
    fs
  • k

    kavinplays

    11/23/2021, 9:05 AM
    he just needs some sleep
  • e

    Erwin

    11/23/2021, 10:28 AM
    Hehe.. no that wasn't it. Turns out I didn't press enter on the second message 😄
  • u

    0xDamian

    11/23/2021, 1:45 PM
    Is it possible to connect and create queries with mongoDB Atlas clusters using serverless function?
  • g

    Greg Brimble | Cloudflare Pages

    11/23/2021, 2:00 PM
    Yes: https://blog.cloudflare.com/workers-adds-support-for-two-modern-data-platforms-mongodb-atlas-and-prisma/
  • u

    0xDamian

    11/23/2021, 5:20 PM
    Thanks, is there maybe a example code?
  • g

    Greg Brimble | Cloudflare Pages

    11/23/2021, 5:36 PM
    Yup. Linked in that post: https://www.mongodb.com/developer/how-to/cloudflare-worker-rest-api-realm
  • t

    thm76

    11/23/2021, 6:32 PM
    Are the "assorted extra libraries" listed somewhere?
  • e

    Erwin

    11/23/2021, 7:46 PM
    https://developers.cloudflare.com/workers/runtime-apis
  • x

    xela

    11/23/2021, 9:25 PM
    probably been asked loads before, but are you able to see logs for pages functions?
  • g

    Greg Brimble | Cloudflare Pages

    11/23/2021, 9:27 PM
    Not possible in the beta right now, unfortunately. Your best bet right now is either local development with
    wrangler pages dev
    or to try/catch and throw errors to a service like Sentry.
  • x

    xela

    11/23/2021, 9:28 PM
    thought so, cheers for the response - managed to catch this one by eye (was passing a null value to cookie.parse) but will do that if i run into more issues :))
  • x

    xmflsct

    11/23/2021, 9:37 PM
    How does this work with Gatsby? Cannot get it working..
  • x

    xela

    11/23/2021, 11:38 PM
    is there a specific wrangler version i need for this? on the latest stable version (npm)
    pages
    isn't a valid subcommand
  • o

    oliverjam

    11/23/2021, 11:42 PM
    Yeah you need the new Wrangler 2 beta https://blog.cloudflare.com/wrangler-v2-beta/
    Copy code
    npm install wrangler@beta
  • x

    xela

    11/23/2021, 11:43 PM
    cheers
  • x

    xela

    11/23/2021, 11:59 PM
    oof
  • w

    Walshy | Pages

    11/24/2021, 12:04 AM
    Yeah you're doing a unicode there with the backslash u.
    \u200B
    for example is zero-width-space
  • w

    wonkrattle

    11/24/2021, 1:54 PM
    @User The alpha is working great by the way
  • g

    Greg Brimble | Cloudflare Pages

    11/24/2021, 1:54 PM
    Wonderful to hear!
  • w

    wonkrattle

    11/24/2021, 1:54 PM
    And once you exclude the functions folder you can rebuild in seconds
  • w

    wonkrattle

    11/24/2021, 1:55 PM
    I would definitely make a documentation page that explains the benefit of doing that by the way
  • g

    Greg Brimble | Cloudflare Pages

    11/24/2021, 1:56 PM
    I was looking at caching yesteday, and realized that we're not sending the same cache-control headers that you'd get in production. Anyone have any thoughts on whether they want here?
  • g

    Greg Brimble | Cloudflare Pages

    11/24/2021, 1:56 PM
    My concern about attaching big ol' cache headers on the static assets locally is that it your browser cache might be a bit too aggressive for local development.
  • g

    Greg Brimble | Cloudflare Pages

    11/24/2021, 1:57 PM
    But, good to have a proper emulation of production 🙃
  • w

    wonkrattle

    11/24/2021, 1:57 PM
    I mean I definitely would not want caching
  • w

    wonkrattle

    11/24/2021, 1:57 PM
    Allowing the option with command line is good, but for most people if you’re testing some thing you don’t want it to cache
1...171819...392Latest