Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supabase serve uses "--no-npm" mode for Deno. Why? This breaks code that needs npm modules. #211

Closed
evelant opened this issue Mar 18, 2023 · 14 comments
Labels
bug Something isn't working

Comments

@evelant
Copy link

evelant commented Mar 18, 2023

Bug report

Describe the bug

I ported my firebase functions to supabase edge functions. In doing so I had to use some npm modules, which I thought was fine since deno supports npm. Upon trying to run my code however I was suprised to be hit with

worker thread panicked Unsupported scheme "npm" for module "npm:/@effect/[email protected]/Exit". Supported schemes: [
    "data",
    "blob",
    "file",
    "http",
    "https",
]

The supabase cli passes "--no-npm" when invoking Deno.

Code is here https://github.com/supabase/cli/blob/a30210717bdb1f3c9d3d5ce940d000971fc1a6da/internal/functions/serve/serve.go#L190

As far as I can tell this isn't documented anywhere by Supabase resulting in a surprise for users. Since Supabase targets people who want to switch from Firebase this is likely to affect almost everyone who attempts to switch as most people use npm modules in their firebase functions.

To Reproduce

  1. Add an npm specifier to your import_map.json such as "@effect/io/": "npm:/@effect/[email protected]/",
  2. run supabase functions serve
  3. Observe that function crashes at runtime due to --no-npm option passed to Deno by supabase cli.

Expected behavior

All Deno features should work. If there's a specific reason why --no-npm is needed it should be clearly documented along with an explanation of how to work around being unable to use npm import specifiers.

Screenshots

N/A

System information

  • OS: macOS
  • Browser N/A
  • Version of supabase-js: N/A
  • Version of Node.js: N/A

Additional context

@evelant evelant added the bug Something isn't working label Mar 18, 2023
@evelant
Copy link
Author

evelant commented Mar 19, 2023

For additional context -- I need to use npm resolutions in Deno because there are some modules (like @effect/io) that tools like esm.sh choke on. The only way to load them in deno is via npm.

@sweatybridge
Copy link

Thank you for clarifying your use case. I've pinged our functions team to help take a look.

@laktek
Copy link
Contributor

laktek commented Mar 20, 2023

@evelant Deno Deploy, the hosting platform we use for functions doesn't support npm specifiers yet. To keep dev/prod parity we disable the npm resolution when serving functions locally.

We will update the docs to mention this limitation.

@evelant
Copy link
Author

evelant commented Mar 20, 2023

@laktek OK thanks. I managed to work around the limitation with a bit of struggle.

I'm running into another issue as well -- globals that should be defined are undefined in the edge runtime (at least locally with supabase functions serve. Specifically performance. A library tries to access performance.now() and it crahes, but only on the edge runtime. Run it locally with deno run -A my_file.ts and performance is accessible and works fine.

@evelant
Copy link
Author

evelant commented Mar 20, 2023

@laktek according to the deno deploy docs performance is an API available on the Deno deploy runtime. https://deno.com/deploy/docs/runtime-api so it appears to be a bug that it's missing in the Supabase edge-runtime.

I want to investigate further but I don't see the Dockerfile for the edge runtime available anywhere. Is it not released on github?

@evelant
Copy link
Author

evelant commented Mar 21, 2023

@sweatybridge @laktek I've looked everywhere and I haven't been able to find source for edge-runtime, could you point me to it? I'd like to investigate the missing globals problem but without the source it's a black box.

@laktek
Copy link
Contributor

laktek commented Mar 21, 2023

@evelant we will be open-sourcing edge-runtime in the coming weeks.

according to the deno deploy docs performance is an API available on the Deno deploy runtime. https://deno.com/deploy/docs/runtime-api so it appears to be a bug that it's missing in the Supabase edge-runtime.

performance API will be included in an upcoming release. We'll update this ticket when the release is made.

@evelant
Copy link
Author

evelant commented Mar 21, 2023

@laktek Can you provide any more information about what is/isn't available in the edge-runtime? The docs are pretty sparse at the moment.

@evelant
Copy link
Author

evelant commented Mar 23, 2023

@laktek I'm seeing a crash when cleaning up my db connection, Deno.errors.BadResource is undefined. Is Deno.errors missing from the supabase edge runtime?

@laktek
Copy link
Contributor

laktek commented Mar 23, 2023

Deno.errors.BadResource is undefined. Is Deno.errors missing from the supabase edge runtime?

@evelant Yep, looks like Deno.errors are missing from the global scope. We'll make a new release to fix it.

BTW, you can check what's available in edge-runtime's global scope by adding console.log(Object.keys(globalThis)) and more specifically for Deno namespace console.log(Object.keys(Deno)) to your function code.

@evelant
Copy link
Author

evelant commented Nov 10, 2023

@laktek Any timeline on when npm specifiers might get supported in the edge runtime?

I'm still stuck without any type checking in editor for edge functions because of multiple bugs with vscode_deno (see supabase/cli#1303 (comment)). Working with edge functions is so painful because of Deno. Npm support might help alleviate that since esm.sh doesn't work well with a lot of packages.

@joshpachner
Copy link

I would also love for npm support.
Or for documentation of how to get around it for certain use cases (we're trying to get Drizzle up and running on the edge functions (so that we can have type help on the edge), and the documentation of using drizzle in deno is literally garbage (true its not supabase's fault))

@zes
Copy link

zes commented Dec 28, 2023

Deno deploy supports npm packages since september 👀

@laktek
Copy link
Contributor

laktek commented Jan 3, 2024

edge-runtime now supports npm modules https://supabase.com/blog/edge-functions-node-npm

@laktek laktek closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants