Files
supabase/apps/docs/content/guides/functions/dependencies.mdx
Colum Ferry 95cf9a78a7 docs(cli): show config examples in TOML and JSONC (#53449)
## Problem

The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0,
but every docs page still shows `config.toml` only. There's also no page
explaining the formats, how to switch, the `$schema` / `#:schema`
declaration, or editor setup, and no reference pages for the new
`supabase config convert` and `supabase config validate` commands.

Linear: CLI-2871

## Solution

- **Dual-format examples from one source.** A new directive
(`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ````
fence with `name=supabase/config.toml` and renders it as
`supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is
generated at build time with `convertCliConfigTomlToJsonc` from
`@supabase/config`, the same converter `supabase config convert` uses,
so authors only write TOML and the JSONC matches what the CLI would
produce (comments included). Inside `<$CodeTabs>` the JSONC is added as
an extra tab.
- **The format choice sticks.** `ConfigCodeTabs` keeps the selected
format in `localStorage`, so choosing JSONC switches every config
example on the page and on later pages.
- **Config reference.** The `usage` examples on
`/guides/local-development/cli/config` use the same tabs (they were
highlighted as Python before), and the intro mentions `config.jsonc`.
The `remotes.<branch_name>` example now uses `[remotes.staging]`, since
`<branch_name>` isn't a valid TOML key.
- **New guide, "Config file formats"**
(`/guides/local-development/cli/config-formats`): which file wins,
minimum CLI version, `convert` and `validate`, schema declaration and
versioning, and editor setup (VS Code trusted domains, Even Better TOML,
Tombi, SchemaStore).
- **CLI reference.** Adds `supabase-config-convert` and
`supabase-config-validate` to the CLI reference nav.
`cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to
the release bot's update in #53463, so the two PRs don't conflict.
- **Content.** About 60 existing config examples across the guides,
including the Branching configuration page, are tagged
`name=supabase/config.toml`. Branching reads `config.json` and
`config.jsonc` as well, and the Branching configuration page now says
so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era
`[inbucket]` before/after snippet stay TOML-only.
- **Format-neutral prose.** Sentences that described the config as
`config.toml` now say "your config file", naming `supabase/config.toml`
and `supabase/config.jsonc` once per page. TOML section syntax in prose
(`max_frequency` under `[auth.email]`) is written as key paths
(`auth.email.max_frequency`), which read the same in both formats.
Headings that named `config.toml` keep their old anchors. Sentences
about what `supabase init` creates still say `config.toml`.
- **Markdown export for agents.**
`internals/generate-guides-markdown.ts` runs the same transform, so the
`.md` pages served to AI agents include the JSONC example after each
TOML one.
- A test converts every tagged example under `content/`, so a broken
TOML example fails tests instead of the build.

New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and
`effect` (the same `effect` version Studio pins).

`config convert` and `config validate` ship in CLI v3.2.0, which is now
stable.

## Review instructions

1. Open `/docs/guides/local-development/seeding-your-database` on the
preview. Switch an example to `supabase/config.jsonc` and check the
other examples on the page switch too.
2. Open `/docs/guides/local-development/cli/config` and check the usage
examples open on JSONC.
3. Read `/docs/guides/local-development/cli/config-formats`.
4. Open `/docs/reference/cli/supabase-config-convert` and
`/docs/reference/cli/supabase-config-validate`.

## Self-review

Ran the `review-the-docs` local self-review (content, pipeline, and
component checks) over the 54 changed pages.

- No blockers. Fixed the nits it found: leftover TOML section syntax in
prose (diff engines, declarative schemas, Branching, the common settings
table on Local and hosted projects), a few long or ungrammatical
sentences, and the conversion follow-up steps on Config file formats,
now a list.
- Links, custom anchors, nav wiring, and frontmatter check out.
- The `.md` export on the preview shows each TOML example followed by
its JSONC version.
- `test-the-docs` deferred: the changed fences are config snippets, and
`ConfigFormats.test.ts` already converts every tagged example. No
procedural steps changed apart from the `config convert` and `config
validate` commands on the new page.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-20 14:34:59 +00:00

181 lines
6.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: 'functions-import-maps'
title: 'Managing dependencies'
description: 'Managing packages and dependencies.'
subtitle: 'Handle dependencies within Edge Functions.'
tocVideo: 'ILr3cneZuFk'
---
## Importing dependencies
Supabase Edge Functions support several ways to import dependencies:
- JavaScript modules from npm (https://docs.deno.com/examples/npm/)
- Built-in [Node APIs](https://docs.deno.com/runtime/manual/node/compatibility)
- Modules published to [JSR](https://jsr.io/) or [deno.land/x](https://deno.land/x)
{/* prettier-ignore */}
```ts
// NPM packages (recommended)
import { createClient } from 'npm:@supabase/supabase-js@2'
// Node.js built-ins
import process from 'node:process'
// JSR modules (Deno's registry)
import path from 'jsr:@std/path@1.0.8'
```
### Using `deno.json` (recommended)
Each function should have its own `deno.json` file to manage dependencies and configure Deno-specific settings. This ensures proper isolation between functions and is the recommended approach for deployment. When you update the dependencies for one function, it won't accidentally break another function that needs different versions.
```json
{
"imports": {
"supabase": "npm:@supabase/supabase-js@2",
"lodash": "https://cdn.skypack.dev/lodash"
}
}
```
You can add this file directly to the function’s own directory:
```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
```
<Admonition type="caution">
It's possible to use a global `deno.json` in the `/supabase/functions` directory for local development, but this approach is not recommended for deployment. Each function should maintain its own configuration to ensure proper isolation and dependency management.
</Admonition>
### 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.
Each function should have its own `import_map.json` file for proper isolation:
```json
# /function-one/import_map.json
{
"imports": {
"lodash": "https://cdn.skypack.dev/lodash"
}
}
```
This JSON file should be located within the function’s own directory. `supabase functions deploy`, `supabase functions serve`, and `supabase start` fail on a function's `import_map.json` unless you point to it with the `import_map` property in your config file (shown below) or `--import-map`. Otherwise, rename it to `deno.json`:
```bash
└── supabase
├── functions
│ ├── function-one
│ │ ├── index.ts
│ │ └── import_map.json # Function-specific import map
```
<Admonition type="caution">
It's possible to use a global `import_map.json` in the `/supabase/functions` directory for local development, but this approach is not recommended for deployment. Each function should maintain its own configuration to ensure proper isolation and dependency management.
</Admonition>
If you’re using import maps with VSCode, update your `.vscode/settings.json` to point to your function-specific import map:
```json
{
"deno.enable": true,
"deno.unstable": ["bare-node-builtins", "byonm"],
"deno.importMap": "./supabase/functions/function-one/import_map.json"
}
```
You can override the default import map location using the `--import-map <string>` flag with serve and deploy commands, or by setting the `import_map` property in your config file:
```toml supabase/config.toml
[functions.function-one]
import_map = "./functions/function-one/import_map.json"
```
---
## Private NPM packages
To use private npm packages, create a `.npmrc` file within your function’s own directory.
<Admonition type="note">This feature requires Supabase CLI version 1.207.9 or higher.</Admonition>
Your function's directory must also contain a `deno.json` or `package.json` file. The file can be empty. If neither file is present, the `.npmrc` file is ignored. This matches the Deno CLI behavior.
```bash
└── supabase
└── functions
└── my-function
├── index.ts
├── deno.json
└── .npmrc # Function-specific npm configuration
```
<Admonition type="caution">
It's possible to use a global `.npmrc` in the `/supabase/functions` directory for local development, but this approach is not recommended for deployment. Each function should maintain its own configuration to ensure proper isolation and dependency management.
</Admonition>
Add your registry details in the `.npmrc` file. Follow [this guide](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc/) to learn more about the syntax of npmrc files.
```bash
# /my-function/.npmrc
@myorg:registry=https://npm.registryhost.com
//npm.registryhost.com/:_authToken=VALID_AUTH_TOKEN
```
After configuring your `.npmrc`, you can import the private package in your function code:
```bash
import package from 'npm:@myorg/private-package@v1.0.1'
```
---
## Using a custom NPM registry
<Admonition type="info">This feature requires Supabase CLI version 2.2.8 or higher.</Admonition>
Some organizations require a custom NPM registry for security and compliance purposes. In such cases, you can specify the custom NPM registry to use via `NPM_CONFIG_REGISTRY` environment variable.
You can define it in the project's `.env` file or directly specify it when running the deploy command:
```bash
NPM_CONFIG_REGISTRY=https://custom-registry/ supabase functions deploy my-function
```
---
## Importing types
If your [environment is set up properly](/docs/guides/functions/development-environment) 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:
```tsx
// @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:
```tsx
/// <reference types="npm:@types/node" />
```