cli: Cannot run edge function due to outdated deno runtime

Bug report

Describe the bug

I wrote a supabase edge function a few weeks ago and successfully deployed it. Yesterday I went to edit it and realized I could not run it locally as I used to.

It appears that as deno continues to update their std library, functions will automatically use newer and newer versions of this library. In this case, my function’s dependencies are now using std 0.153.0 which is incompatible with deno 1.20.3 (which is what supabase uses).

In order to get my application to work, I either need to find a way to force the std library down to 0.152.0 or get supabase to run something newer than 1.20.0. Since I don’t import std myself but rather my dependencies do, I don’t see a way to control which version of std I get.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a new supabase function: supabase functions new hello
  2. Edit the function and add a dependency such as import "https://esm.sh/plaid@11.0.0";
  3. Run the function with supabase supabase functions serve hello --debug and observe the error output
  4. Run the function with deno cli 1.20.3 and observe the same error: deno run supabase/functions/hello/index.ts
  5. Run the function with deno cli 1.26.0 and observe that it works because 1.26.0 is compatible with std 0.153.0 while deno 1.20.3 is not

In case it helps, in my testing I used asdf as a version manager to be able to switch between deno versions.

Expected behavior

I expect there to be a way to force either the deno version or library version or both when running locally as well as remote. Otherwise, a deterministic runtime environment is not possible and this reduces the viability of the edge functions feature.

System information

  • OS: macOS 12.6 (M1)
  • Version of supabase-js: 1.35.6
  • Version of Deno: 1.20.3 and 1.26.0
  • Version of supabase-cli: 1.5.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Good news - we’ve removed the Deno version pin in https://github.com/supabase/cli/pull/601! Can you check if your function can be deployed now? (You might need to update the CLI)

Here’s the snippet I used to test this:

import { serve } from "https://deno.land/std@0.165.0/http/server.ts";
import Plaid from "https://esm.sh/plaid@12.0.0?target=deno&no-check";
import Stripe from "https://esm.sh/stripe@11.0.0?target=deno&no-check";
import Opine from "https://deno.land/x/opine@2.3.3/mod.ts";

console.log(Plaid, Stripe, Opine);

serve(async (req) => {
  try {
    return new Response();
  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
      status: 400,
    });
  }
});

Hello @soedirgo

When I try with &deno-std=0.132.0 for each libraries I import, it’s works for me.

This is good progress 👍

Can you try this?

import { serve } from "https://deno.land/std@0.132.0/http/server.ts";
// Deno CLI v1.20.3 is compatible with Deno std 0.132.0: https://raw.githubusercontent.com/denoland/dotland/main/versions.json
// append `&deno-std=0.132.0` on all esm.sh imports
import Plaid from "https://esm.sh/plaid@11.0.0?target=deno&deno-std=0.132.0";
import Stripe from "https://esm.sh/stripe@10.13.0?target=deno&deno-std=0.132.0";

console.log(Plaid, Stripe);

serve(async (req) => {
  try {
    return new Response();
  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
      status: 400,
    });
  }
});

Sure enough, that fixed it! Thanks @soedirgo 😄

Good call! That does appear to work as far as running it. Now I’m hitting a function size limit when I try to deploy it to supabase. That’s out of scope for this ticket though.

@soedirgo your suggestion worked for my plaid lib import from esm.sh but did not work for my deno.land import of Opine 2.3.3. This is expected behavior and would normally mean that Opine needs an update but that project has been moved to maintenance mode in favor of using express via deno 1.25’s npm compatibility mode. (I have my own separate opinions about their decision to do so before npm compat is stable but that’s outside the scope of this ticket)

So now I have plaid working but Opine failing with the same error. My options are either ditch opine and lose an express-like syntax for my code wait until Supabase updates to at least deno runtime 1.25 so I can use express itself. Any other workaround ideas?

Just restating for posterity, it really seems like Supabase should just always match the current deno runtime version so that it behaves exactly the same as deno deploy. That way, all issues are deno issues instead of Supabase issues.

Of course! That said, many other cloud function providers allow the dev to either specify the runtime version or provide a list of acceptable versions. I feel like this would probably be important to ensure that deployed functions do not suddenly break if the supabase backend is updated. Or is a deployed function always run with the same deno version it was deployed with?