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

    Isaac McFadyen | YYZ01

    03/15/2022, 2:51 AM
    😦 TS should work when importing
    .js
    files and there's a
    .ts
    equivilant?
  • i

    Isaac McFadyen | YYZ01

    03/15/2022, 2:51 AM
    Does it not for you?
  • b

    Bytesource

    03/15/2022, 2:54 AM
    Do you mean importing
    xy.ts
    as
    xy.js
    should work (because at the time it's imported,
    xy.ts
    has already been transformed to
    xy.js
    )?
  • i

    Isaac McFadyen | YYZ01

    03/15/2022, 2:55 AM
    Yeah, exactly.
  • i

    Isaac McFadyen | YYZ01

    03/15/2022, 2:56 AM
    And Typescript should realize this and still give you autocompletion.
  • i

    Isaac McFadyen | YYZ01

    03/15/2022, 2:56 AM
    That's the way I've seen, at least.
  • b

    Bytesource

    03/15/2022, 2:56 AM
    Fantastic, let me try this real quick.
  • b

    Bytesource

    03/15/2022, 3:21 AM
    Importing
    .ts
    as
    .js
    still didn't work on the server:
    Copy code
    11:10:10.125    ✘ [ERROR] Could not resolve "../credentials.js"
    11:10:10.126    
    11:10:10.126        ../../../buildhome/repo/functions/contact/index.ts:4:22:
    11:10:10.126          4 │ import { Creds } from '../credentials.js';
    11:10:10.126            ╵                       ~~~~~~~~~~~~~~~~~~~
    11:10:10.126    
    11:10:10.128    1 error(s) and 0 warning(s) when compiling Worker.
    11:10:10.129    Build failed with 1 error:
    11:10:10.129    ../../../buildhome/repo/functions/contact/index.ts:4:22: ERROR: Could not resolve "../credentials.js"
    Maybe the working directly on local
    functions
    and on the server is different? But then again, importing
    .js
    files works just fine. Anyway, this is the file structure of my
    functions
    folder:
    Copy code
    functions/
      contact/
        index.ts
    _middleware.ts
    credentials.ts
    Lastly, this is the line where I import
    credentials.ts
    into `index.ts`:
    import { Creds } from '../credentials.js';
  • j

    JacobParis

    03/15/2022, 9:13 AM
    Yes you can do this
  • j

    JacobParis

    03/15/2022, 9:14 AM
    If you compile a function into
    /public/_worker.js
    it will be uploaded as the Page function
  • j

    JacobParis

    03/15/2022, 9:14 AM
    https://github.com/jacobPARIS/remix-cloudflare-prisma/blob/main/build-server.mjs#L36-L39
  • j

    JacobParis

    03/15/2022, 9:15 AM
    Look at the outfile, the entrypoint, and then you can see I'm using esbuild-plugin-alias there too
  • n

    n

    03/15/2022, 12:31 PM
    I've noticed a possible bug where calling the same functions endpoint with different parameters at the same time at page load sometimes results in one or both functions crashing with error 1101. This only happens in deployed functions. Locally they never crash and when a page only calls a deployed function once, it never crashes, which is why I believe it is an issue with functions and not the code being run. As a workaround, I'm using client-side retries.
  • e

    Erwin

    03/15/2022, 1:09 PM
    Hmm.. are you by any chance awaiting a promise in a global scope?
  • n

    n

    03/15/2022, 1:22 PM
    no
  • e

    Erwin

    03/15/2022, 1:35 PM
    The multiple requests are coming from the same browser right? One browser makes multiple requests at the same time?
  • n

    n

    03/15/2022, 1:36 PM
    yes--I have pages on my site that call the same functions endpoint multiple times*
  • e

    Erwin

    03/15/2022, 1:37 PM
    There is some kind of race condition going on in your code
  • e

    Erwin

    03/15/2022, 1:39 PM
    Which leads to an uncaught exception.. I would catch all exceptions at the top level and return that in 500 response header.. so that you can easily see what the exception is when you reproduce it.
  • n

    n

    03/15/2022, 1:40 PM
    there is a top level catch, but I might not be processing that correctly--let me take a look
  • e

    Erwin

    03/15/2022, 1:41 PM
    It is possible the runtime triggers the exception, in which case you can't catch it.. In that case I would stream the logs from your dashboard.
  • n

    n

    03/15/2022, 1:42 PM
    where in the dashboard can I view logs from pages functions? I must have missed it earlier
  • e

    Erwin

    03/15/2022, 1:44 PM
    Logs tab
  • n

    n

    03/15/2022, 1:53 PM
    I don't have regular workers set up so I don't think I can access the logs tab
  • n

    n

    03/15/2022, 1:54 PM
    I created a regular worker and see the logs tab for it, but can't access logs for my pages function
  • n

    n

    03/15/2022, 1:57 PM
    I'll look into your earlier suggestion and report back if it seems to be a runtime exception
  • e

    Erwin

    03/15/2022, 1:59 PM
    Ahh.. yeah ofc.. it is Pages.. :/
  • e

    Erwin

    03/15/2022, 1:59 PM
    Maybe @User or @User know how to stream them through wrangler
  • g

    Greg Brimble | Cloudflare Pages

    03/15/2022, 2:33 PM
    npx wrangler pages dev
    will stream all your `console.log`s to the terminal in local dev
  • i

    Isaac McFadyen | YYZ01

    03/15/2022, 2:33 PM
    Wait WHAT?!
1...959697...392Latest