new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Supabase · Edge Functions · all subjects

edge functions/dependencies

23 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Import types for built-in Node APIs in Edge Functions

To include types for built-in Node APIs in Edge Functions, add the following line at the top of your imports: `/// <reference types="npm:@types/node" />`

Edge Functions support multiple dependency import methods

Supabase Edge Functions support importing dependencies from: JavaScript modules from npm using the npm: prefix, built-in Node APIs using the node: prefix, and modules published to JSR or deno.land/x registries.

deno.json recommended for managing Edge Function dependencies

Each Edge Function should have its own deno.json file in the function's directory to manage dependencies and configure Deno-specific settings. This ensures proper isolation between functions and prevents one function's dependency update from breaking another. The deno.json file uses an 'imports' object to map package names to their sources.

deno.json file location for Edge Functions

The deno.json file should be placed directly within each function's own directory, at the same level as the index.ts file. For example: supabase/functions/function-one/deno.json

Global deno.json not recommended for Edge Function deployment

While it is possible to use a global deno.json in the /supabase/functions directory for local development, this approach is not recommended for deployment. Each function should maintain its own configuration to ensure proper isolation and dependency management.

deno.json example with npm and CDN imports

Example deno.json configuration: ```json { "imports": { "supabase": "npm:@supabase/supabase-js@2", "lodash": "https://cdn.skypack.dev/lodash" } } ```

Import maps are legacy approach for Edge Function dependencies

Import maps (import_map.json) are a legacy way to manage dependencies similar to a package.json file. While still supported, deno.json is recommended. If both deno.json and import_map.json exist, deno.json takes precedence.

import_map.json file location and configuration

Each function should have its own import_map.json file located within the function's own directory at the same level as index.ts. The file contains an 'imports' object mapping package names to their sources. Global import_map.json in /supabase/functions directory is possible for local development but not recommended for deployment.

VSCode configuration for function-specific import maps

When using import maps with VSCode, update .vscode/settings.json to point to the function-specific import map. Example: ```json { "deno.enable": true, "deno.unstable": ["bare-node-builtins", "byonm"], "deno.importMap": "./supabase/functions/function-one/import_map.json" } ```

Override import map location with CLI flag or config.toml

The default import map location can be overridden using the --import-map <string> flag with serve and deploy commands, or by setting the import_map property in config.toml. Example in config.toml: ```toml [functions.my-function] import_map = "./supabase/functions/function-one/import_map.json" ```

Private npm packages require .npmrc file in function directory

To use private npm packages in Edge Functions, create a .npmrc file within the function's own directory at the same level as index.ts and deno.json. This feature requires Supabase CLI version 1.207.9 or higher.

Private npm packages .npmrc configuration example

Example .npmrc file for private npm packages: ```bash @myorg:registry=https://npm.registryhost.com //npm.registryhost.com/:_authToken=VALID_AUTH_TOKEN ``` After configuring .npmrc, import the private package like: `import package from 'npm:@myorg/private-package@v1.0.1'`

Global .npmrc not recommended for Edge Function deployment

While possible to use a global .npmrc in /supabase/functions directory for local development, this approach is not recommended for deployment. Each function should maintain its own .npmrc configuration to ensure proper isolation and dependency management.

Custom npm registry via NPM_CONFIG_REGISTRY environment variable

Organizations can specify a custom npm registry using the NPM_CONFIG_REGISTRY environment variable. This feature requires Supabase CLI version 2.2.8 or higher. The variable can be defined in the project's .env file or specified directly when running the deploy command: `NPM_CONFIG_REGISTRY=https://custom-registry/ supabase functions deploy my-function`

Importing types in Edge Functions

If a module is exporting types and your environment is set up properly, imports will have types and autocompletion support. Some npm packages may not ship with types and require importing from a separate package using the @deno-types directive: `// @deno-types="npm:@types/express@^4.17" import express from 'npm:express@^4.17'`

Import React Email and Resend in Edge Functions

React Email components and Resend can be imported from npm packages in Edge Functions: `import { renderAsync } from 'npm:@react-email/components@^1'`, `import { Resend } from 'npm:resend@^6'`, and `import React from 'npm:react@^19'`.

Importing npm packages in Deno via npm: prefix

Import npm packages in Supabase Edge Functions using the npm: prefix, such as import { Package } from 'npm:package-name@^version'. No npm install is required.

Import JSR packages for Deno

Packages from the JavaScript Registry (JSR) can be imported using the `jsr:` prefix. For example, `import 'jsr:@supabase/functions-js/edge-runtime.d.ts'` imports type definitions from the Supabase Functions JSR package.

Import dependencies in Deno with npm: prefix

In Supabase Edge Functions using the Deno runtime, external npm packages can be imported using the `npm:` prefix. For example, `import { Bot } from 'npm:grammy@^1'` imports the grammy package. No local package installation is required.

Deno import maps for MCP server dependencies

The template uses Deno's import maps in deno.json to manage npm packages. Configuration includes compilerOptions with lib: ['deno.window', 'deno.ns'] and strict: true, plus imports for hono@^4.6.14, mcp-lite@0.8.2, and zod@^4.1.12.

FCM JWT uses google-auth-library

For Firebase Cloud Messaging, the google-auth-library@^10 npm package provides a JWT class for generating access tokens. Initialize JWT with email (clientEmail), key (privateKey), and scopes ['https://www.googleapis.com/auth/firebase.messaging']. Call jwtClient.authorize() with a callback to get tokens.access_token.

Custom import_map for function dependencies

Configure custom dependencies for a specific function by setting import_map in the [functions.function-name] section of config.toml, pointing to a path relative to config.toml (e.g., './functions/image-processor/import_map.json').

Import Redis from Upstash npm package in Edge Functions

Import Redis class using `import { Redis } from 'npm:@upstash/redis@^1'`. The Redis constructor takes an object with url and token properties set from environment variables. The url should come from UPSTASH_REDIS_REST_URL and token from UPSTASH_REDIS_REST_TOKEN.

Give your agent this brain