Home

Managing dependencies

Managing packages and dependencies.

Developing with Edge Functions is similar to developing with Node.js, but with a few key differences. This guide will help you understand how to manage your dependencies.

Importing dependencies#

Supabase Edge Functions support:

We recommend using esm.sh for importing modules that are published to npm. To do so, put https://esm.sh/ in front of the package name. For example, import the supabase-js package like this:


_10
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'

note:npm support

Full support for NPM is under development and coming soon.

Importing Types#

If your environment is set up properly and the module you're importing is exporting types, the import will have types and autocompletion support.

Using Import Maps#

An Import Map is similar to a package.json file. They are a way to manage your dependencies. Consider this code:


_10
// without import maps:
_10
import lodash from 'https://cdn.skypack.dev/lodash'
_10
_10
// with import maps:
_10
import lodash from 'lodash'

You can accomplish this using an Import Map, which is a JSON file with the following:

supabase/functions/import_map.json

_10
{
_10
"imports": {
_10
"lodash": "https://cdn.skypack.dev/lodash"
_10
}
_10
}

We recommend creating one import_map.json within the /supabase/functions folder, similar to a package.json file, to define imports that can be used across all of your project's functions.


_10
└── supabase
_10
├── functions
_10
│ ├── import_map.json # A top-level import map to use across functions..
_10
│ ├── function-one
_10
│ │ └── index.ts
_10
└── config.toml

Alternatively, you can create one import_map.json file in each function folder, which will take priority over a top-level file.

You can override this default behavior by providing the --import-map <string> flag to the serve and deploy commands.

Configuring VSCode#

In order for vscode to understand the imports correctly, you need to specify the deno.importMap flag in your .vscode/settings.json file:

settings.json

_10
{
_10
"deno.enable": true,
_10
"deno.unstable": true,
_10
"deno.importMap": "./supabase/functions/import_map.json"
_10
}

For a full guide on developing with Deno in Visual Studio Code, see this guide.