3

I try to work with supabase edge functions in a Deno environment in IntelliJ Ultimate. The corresponding plugin is already installed but inside my supabase folder the functions I wanna create do not support Deno IntelliSense which makes things quite hard.

Folder Structure: enter image description here

I don't know why my IntelliSense breaks when working with Deno and/or how to retrieve the correct types from packages imported via import_map.json

import_map.json

{
  "imports": {
    "stripe": "https://esm.sh/stripe@11.12.0?target=deno",
    "std/server": "https://deno.land/std@0.177.0/http/server.ts"
  }
}

index.ts inside my 'get-ticket-information' function folder (The code is probably correct, but shows me errors because of missing types):

import { serve } from 'std/server'
import Stripe from 'stripe'

const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY') as string, {
  apiVersion: '2022-11-15',
  httpClient: Stripe.createFetchHttpClient(),
})

When trying to deploy to supabase via

 supabase functions deploy --no-verify-jwt get-ticket-information --debug

I do receive the following error too:

Uncaught (in promise) Error: Relative import path "http" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v108/@types/node@16.18.12/http.d.ts"
      const ret = new Error(getStringFromWasm0(arg0, arg1));

Markus G.
  • 1,620
  • 2
  • 25
  • 49
  • did you try specifying a path to your `import.map.json` in **Settings | Languages & Frameworks | Deno, Init command**? By default, the IDE expects it to be located in the project root. If it's located in a subfolder, the path to it has to be specified in init command – lena Feb 28 '23 at 15:36
  • Yes, changed it to './supabase/functions/import_map.json'. Still won't work. – Markus G. Mar 02 '23 at 08:01
  • Typescript doesn't support import-map yet. In vscode, we need to add `paths` in tsconfig.json or jscofig.json. – Anil kumar Jun 08 '23 at 07:18
  • From feb 22, we don't need to create separate file `import_map.json`. Add `imports` key in `deno.json`. Read more [issues/15816](https://github.com/denoland/deno/issues/15816) – Anil kumar Jun 08 '23 at 07:26

1 Answers1

1

Regarding the runtime error:

The Supabase CLI documentation for supabase functions deploy suggests that you must provide a path to the import map at the time of invocation:

supabase functions deploy

Deploy a Function to the linked Supabase project.

Basic usage:

supabase functions deploy <Function name> [flags]

Flags:

--import-map <string>

Path to import map file.

...cont.


Regarding import maps as they relate to IDE integration and types:

This has already been covered on Stack Overflow here, and is also covered in the manual in section 3.3: Import Maps.

jsejcksn
  • 27,667
  • 4
  • 38
  • 62