davecancode
davecancodeβ€’3mo ago

How to import qstash into deno edge function?

Hi, simple question, I think, but I can't figure out. I want to import this module into my deno edge function so I can use the Client and Receiver in some webhooks for background jobs: https://deno.land/x/upstash_qstash@v2.5.2 I can't get the import to work. Not sure if it requires an import map or I can just declare it at the top of the edge function file in typescript.
5 Replies
davecancode
davecancodeβ€’3mo ago
I'm using this on supabase but they don't have examples for deno land imports: https://supabase.com/docs/guides/functions/import-maps#importing-dependencies
Supabase
Managing dependencies | Supabase Docs
Managing packages and dependencies.
davecancode
davecancodeβ€’3mo ago
I can get this one to work for sentry: import * as Sentry from 'https://deno.land/x/sentry/index.mjs' and this one to work for the standard libary path module: import { extname } from 'https://deno.land/std@0.224.0/path/mod.ts'
Deno AI Helper
Deno AI Helperβ€’3mo ago
To import the upstash_qstash module into your Deno Edge function, you should be able to directly import it using the URL to the module. According to the documentation, Deno supports loading and executing code from URLs, much like you would use a <script> tag in the browser. This means you can import modules directly by specifying their URLs. Here's how you can import the Client and Receiver from the upstash_qstash module at version v2.5.2:
import { Client, Receiver } from "https://deno.land/x/upstash_qstash@v2.5.2/mod.ts";
import { Client, Receiver } from "https://deno.land/x/upstash_qstash@v2.5.2/mod.ts";
You can place this import statement at the top of your TypeScript file that defines the edge function. Since Deno requires explicit file extensions in imports, make sure that the URL you are importing from includes the .ts extension if it's a TypeScript module. In this case, the mod.ts is the main module file for the upstash_qstash package. If you encounter any issues with this import, such as conflicts with other dependencies or the need to specify versioning more granularly, you might consider using an import map. However, for a straightforward import like this, an import map should not be necessary. Remember to handle any permissions or configurations that might be required by the module within your Deno Edge function environment. πŸ¦•
davecancode
davecancodeβ€’3mo ago
Okay, so I was on the right track. I'm importing in my edge functions like this (two separate files): import { Client } from 'https://deno.land/x/upstash_qstash@v2.5.2/src/index.ts' import { Receiver } from 'https://deno.land/x/upstash_qstash@v2.5.2/src/index.ts' Which gives me this error in VS Code: Module '"https://deno.land/x/upstash_qstash@v2.5.2/src/index.ts"' has no exported member 'Client'.deno-ts(2305) If I try to deploy to supabase with CLI (as a test to see if my local dev environment is borked or something) I get this error: Error: failed to load 'https://deno.land/x/upstash_qstash@v2.5.2/src/receiver': Module not found "https://deno.land/x/upstash_qstash@v2.5.2/src/receiver". 🐞 If I try it with mod.ts instead I get this error in VS Code: Uncached or missing remote URL: https://deno.land/x/upstash_qstash@v2.5.2/src/mod.ts πŸ†
I was able to get around this issue by using the npm style import: import { Receiver } from 'npm:@upstash/qstash' 🀷