Markus G.
Markus G.

Reputation: 1718

Deno import_map.json for supabase

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/[email protected]?target=deno",
    "std/server": "https://deno.land/[email protected]/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/[email protected]/http.d.ts"
      const ret = new Error(getStringFromWasm0(arg0, arg1));

Upvotes: 3

Views: 2711

Answers (2)

Unkn0wn0x
Unkn0wn0x

Reputation: 1167

You need to specify the paths like following:

import_map.json

{
    "imports": {
      "std/http/server.ts": "https://deno.land/[email protected]/http/server.ts"
    }
}

You correspondending index.ts:

import { serve } from 'std/http/server.ts';

In the latest version(s) of deno, this package is deprecated, instead you should use Deno.serve() as a global function without any imports (if you plan to use the latest version of deno).

Upvotes: 0

jsejcksn
jsejcksn

Reputation: 33796

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.

Upvotes: 1

Related Questions