The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: add deno.json support for edge functions (#30261)
Julien Goux5b07151d88bf
diff --git a/apps/docs/content/guides/functions/import-maps.mdx b/apps/docs/content/guides/functions/import-maps.mdxindex 72d25194ff9..858aa3d2f15 100644--- a/apps/docs/content/guides/functions/import-maps.mdx+++ b/apps/docs/content/guides/functions/import-maps.mdx@@ -8,59 +8,51 @@ tocVideo: 'ILr3cneZuFk'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+## Managing dependencies-Supabase Edge Functions support:+There are two ways to manage your dependencies in Supabase Edge Functions:-- The Deno [standard library](https://deno.land/std)-- JavaScript modules from npm (https://docs.deno.com/examples/npm/)-- Built-in [Node APIs](https://docs.deno.com/runtime/manual/node/compatibility)-- Third party modules published to [JSR](https://jsr.io/) or [deno.land/x](https://deno.land/x)+### Using deno.json (Recommended)-You can import npm modules using the `npm:` specifier or via CDNs like [esm.sh](https://esm.sh). For example, to import the `supabase-js` package:+<Admonition type="info">-```ts-import { createClient } from 'npm:@supabase/supabase-js@2'-```+This feature requires Supabase CLI version 1.215.0 or higher.-If you are migrating an existing Node app and if it uses a built-in Node APIs, you can import them to Deno using `node:` specifiers. For example, if your code uses `process.env`, you can import it as follows:+</Admonition>-```ts-import process from 'node:process'-```+Each function can have its own `deno.json` or `deno.jsonc` file to manage dependencies and configure Deno-specific settings. For a complete list of supported options, see the [official Deno configuration documentation](https://docs.deno.com/runtime/manual/getting_started/configuration_file).-You can learn more about `npm:` specifiers and Node built-in APIs, in [Deno's documentation](https://docs.deno.com/runtime/manual/node/npm_specifiers).--## Importing types--If your [environment is set up properly](/docs/guides/functions/local-development) and the module you're importing is exporting types, the import will have types and autocompletion support.--Some npm packages may not ship out of the box types and you may need to import them from a separate package. You can specify their types with a `@deno-types` directive:--```ts-// @deno-types="npm:@types/express@^4.17"-import express from 'npm:express@^4.17'+```json supabase/functions/my-function/deno.json+{+ "imports": {+ "lodash": "https://cdn.skypack.dev/lodash"+ }+}```-To include types for built-in Node APIs, add the following line to the top of your imports:+This allows you to use simplified imports:```ts-/// <reference types="npm:@types/node" />+import lodash from 'lodash'```-## Using import maps--An [Import Map](https://github.com/WICG/import-maps#the-import-map) is similar to a `package.json` file. They are a way to manage your dependencies. Consider this code:--```ts-// without import maps:-import lodash from 'https://cdn.skypack.dev/lodash'+The recommended file structure when using `deno.json`:-// with import maps:-import lodash from 'lodash'+```bash+└── supabase+ ├── functions+ │ ├── function-one+ │ │ ├── index.ts+ │ │ └── deno.json # Function-specific Deno configuration+ │ └── function-two+ │ ├── index.ts+ │ └── deno.json # Function-specific Deno configuration+ └── config.toml```-You can accomplish this using an Import Map, which is a JSON file with the following:+### Using Import Maps (Legacy)++Import Maps are a legacy way to manage dependencies, similar to a `package.json` file. While still supported, we recommend using `deno.json`. If both exist, `deno.json` takes precedence.```json supabase/functions/import_map.json{@@ -70,45 +62,87 @@ You can accomplish this using an Import Map, which is a JSON file with the follo}```-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.+The import map should be placed in the `/supabase/functions` folder and will be applied to all functions:```bash└── supabase├── functions- │ ├── import_map.json # A top-level import map to use across functions..+ │ ├── import_map.json # Top-level import map for all functions│ ├── function-one│ │ └── index.ts+ │ └── function-two+ │ └── index.ts└── 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.+You can override the import map location using the `--import-map <string>` flag with `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:+If using import maps with VSCode, update your `.vscode/settings.json`:```json settings.json{"deno.enable": true,"deno.unstable": ["bare-node-builtins",- "byonm",- "sloppy-imports",- "unsafe-proto",- "webgpu",- "broadcast-channel",- "worker-options",- "cron",- "kv",- "ffi",- "fs",- "http",- "net"+ "byonm"+ // ... other flags ...],"deno.importMap": "./supabase/functions/import_map.json"}```-For a full guide on developing with Deno in Visual Studio Code, see [this guide](https://deno.land/[email protected]/vscode_deno).+You can override the default import map location in two ways:++1. Using the `--import-map <string>` flag with `serve` and `deploy` commands+2. Setting the `import_map` property in your `config.toml` file for specific functions:++```toml supabase/config.toml+[functions.my-function]+import_map = "./supabase/functions/my-function/custom_import_map.json"+```++For more configuration options, see the [CLI Configuration documentation](/docs/guides/local-development/cli/config#functions.function_name.import_map).++## Importing dependencies++Supabase Edge Functions support several ways to import dependencies:++- The Deno [standard library](https://deno.land/std)+- JavaScript modules from npm (https://docs.deno.com/examples/npm/)+- Built-in [Node APIs](https://docs.deno.com/runtime/manual/node/compatibility)+- Third party modules published to [JSR](https://jsr.io/) or [deno.land/x](https://deno.land/x)++### NPM Modules++You can import npm modules using the `npm:` specifier:++```ts+import { createClient } from 'npm:@supabase/supabase-js@2'+```++### Node.js Built-ins++For Node.js built-in APIs, use the `node:` specifier:++```ts+import process from 'node:process'+```++Learn more about npm specifiers and Node built-in APIs in [Deno's documentation](https://docs.deno.com/runtime/manual/node/npm_specifiers).++## Importing types++If your [environment is set up properly](/docs/guides/functions/local-development) and the module you're importing is exporting types, the import will have types and autocompletion support.++Some npm packages may not ship out of the box types and you may need to import them from a separate package. You can specify their types with a `@deno-types` directive:++```ts+// @deno-types="npm:@types/express@^4.17"+import express from 'npm:express@^4.17'+```++To include types for built-in Node APIs, add the following line to the top of your imports:++```ts+/// <reference types="npm:@types/node" />+```