Skip to content

Issues serving Edge Functions locally

如果 supabase functions serve 失败或者你在本地运行 Edge Functions 遇到问题,按照这些步骤来排查和解决问题。

🌐 If supabase functions serve fails or you're having trouble running Edge Functions locally, follow these steps to diagnose and resolve the issue.

调试步骤 #

🌐 Debugging steps

使用调试模式 #

🌐 Use debug mode

使用 --debug 标志运行 serve 命令以获取详细输出:

🌐 Run the serve command with the --debug flag for detailed output:

supabase functions serve your-function --debug

检查端口可用性 #

🌐 Check port availability

确保所需的端口可用。Supabase CLI 默认使用端口 54321 和 8081:

🌐 Ensure the required ports are available. The Supabase CLI uses ports 54321 and 8081 by default:

# Check if port 54321 is in use
lsof -i :54321
# Check if port 8081 is in use
lsof -i :8081

如果这些端口正在使用,停止使用它们的进程或者配置其他端口。

🌐 If these ports are in use, stop the processes using them or configure different ports.

常见问题 #

🌐 Common issues

端口冲突 #

🌐 Port conflicts

可能有其他进程正在使用所需的端口。检查一下:

🌐 Another process may be using the required ports. Check for:

  • 本地运行的其他 Supabase 项目
  • Docker 容器
  • 其他开发服务器

如果冲突来自另一个 Supabase 项目,请使用实验性的 supabase stack 命令同时运行两个项目。它们会为每个本地项目分配自己的端口。先开启这些命令,并从每个项目的 config.toml 中移除固定端口。参见 运行多个本地项目。

🌐 If the conflict comes from another Supabase project, run both projects at the same time with the experimental supabase stack commands. They assign each local project its own ports. Turn on the commands and remove the fixed ports from each project's config.toml first. See Running multiple local projects.

Deno 缓存问题 #

🌐 Deno cache issues

如果你遇到模块解析问题,可以清理 Deno 缓存:

🌐 Clear the Deno cache if you're experiencing module resolution problems:

deno cache --reload /path/to/function/index.ts

环境变量 #

🌐 Environment variables

确保你的 .env 文件已正确配置并且可以被命令行访问。

🌐 Make sure your .env file is properly configured and accessible to the CLI.

获得更多帮助 #

🌐 Getting more help

如果问题仍然存在,可以在以下仓库中搜索类似的错误信息:

🌐 If the problem persists, search the following repositories for similar error messages:

如果这些命令的输出不能解决问题,可以通过 Supabase 仪表板(点击右上角的“帮助”按钮)提交支持请求,并附上所有输出和命令的详细信息。

🌐 If the output from these commands does not help resolve the issue, open a support ticket via the Supabase Dashboard (by clicking the "Help" button at the top right) and include all output and details about your commands.

额外资源 #

🌐 Additional resources