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

    James

    12/18/2021, 12:51 AM
    Are you running them locally with
    wrangler pages dev
    , or live? The experience for debugging Pages functions isn't perfect yet, but if you can share your repo, hopefully we can spot something 😄
  • f

    Fredthedoggy

    12/18/2021, 12:51 AM
    pages dev
  • f

    Fredthedoggy

    12/18/2021, 12:51 AM
    and it's not pushed to a repo yet, since it's just me putting some libraries together
  • f

    Fredthedoggy

    12/18/2021, 12:51 AM
    to test stuff
  • f

    Fredthedoggy

    12/18/2021, 12:51 AM
    no actual code exists
  • f

    Fredthedoggy

    12/18/2021, 12:51 AM
    but it has a
    functions/api
    folder
  • f

    Fredthedoggy

    12/18/2021, 12:52 AM
    with a
    details.ts
    file
  • r

    richardwong

    12/18/2021, 6:52 AM
    Hi, does functions support importing third party npm package ? When i using
    jsc8
    in function, it won't work.
  • r

    richardwong

    12/18/2021, 6:52 AM
  • r

    richardwong

    12/18/2021, 6:53 AM
    I'm using
    wrangler 0.0.0-beta.6
  • r

    richardwong

    12/18/2021, 6:53 AM
    and this is my code
  • r

    richardwong

    12/18/2021, 6:53 AM
  • p

    pxkq

    12/18/2021, 8:21 AM
    Are you proxying your win though Wrangler? Search for
    --proxy
  • p

    pxkq

    12/18/2021, 8:21 AM
    Workers don't support nodejs libraries
  • r

    richardwong

    12/18/2021, 10:43 AM
    Yes, i'm using --proxy
  • r

    richardwong

    12/18/2021, 10:44 AM
    wrangler pages dev ./dist --proxy=3000
  • r

    richardwong

    12/18/2021, 10:44 AM
    But
    jsc8
    is compiled in this demo
    https://github.com/Macrometacorp/tutorial-cloudflare-bookstore
  • r

    richardwong

    12/18/2021, 10:45 AM
    I found that
    require('path')
    cause the error, but why this old worker-sites demo works
  • p

    pxkq

    12/18/2021, 10:57 AM
    I don't know, I'm not familiar with
    tutorial-cloudflare-bookstore
    or
    jsc8
    , but from its dependencies it looks like nodejs to me, and as far as I know cloudflare workers don't support that. Are you able to run
    tutorial-cloudflare-bookstore
    yourself?
  • r

    richardwong

    12/18/2021, 11:25 AM
    Yes, I can run it locally
  • m

    MrBBot

    12/18/2021, 3:05 PM
    Hey! 👋 It looks like that demo is using a
    type = "webpack"
    Wrangler project. This uses Webpack 4 to bundle the code which automatically polyfills Node.js built-in modules like
    path
    . Pages functions uses esbuild for bundling instead which doesn't do this by default. Afaik, pages doesn't let you customise this, unless you use advanced mode: https://developers.cloudflare.com/pages/platform/functions#advanced-mode.
  • f

    Fredthedoggy

    12/18/2021, 3:30 PM
    Proxy is on by default according to it
  • f

    Fredthedoggy

    12/18/2021, 3:30 PM
    It always finds a random port for the proxy
  • s

    Skye

    12/18/2021, 6:16 PM
    Hi. How would I access query parameters in pages functions? Was looking for it under context.params but that appears to be different
  • h

    HardAtWork

    12/18/2021, 6:21 PM
    const params = new URL(context.request.url).searchParams;
  • s

    Skye

    12/18/2021, 6:22 PM
    thanks :)
  • s

    Skye

    12/18/2021, 6:23 PM
    are these an object or some other format?
  • w

    Walshy | Pages

    12/18/2021, 6:23 PM
    https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
  • s

    Skye

    12/18/2021, 6:23 PM
    perfect, ty
  • s

    Skye

    12/18/2021, 8:51 PM
    I notice it says this in the logs. Does this mean all routes are counted as function routes? Rather than just the specific routes I create 🤔. I've created a function for one file (no wildcards/etc) and it appears to be counting it for every request
    Copy code
    20:46:28.467    Compiling worker to "/opt/pages/functions/user-worker.js"
    20:46:28.477    Finished in 42ms.
1...464748...392Latest