Netlify Function Deployment Issue: Background Function Returns 404
Problem Description
I’m experiencing an issue with my Netlify background function deployment. When my application tries to call the background function, it consistently returns a 404 Not Found error. I’ve followed the documentation for setting up background functions and confirmed that the function works locally with netlify dev
.
Project Details
- Framework: Next.js 15 app router
- Function Type: Background function (for long-running data processing)
- Deployment Method: Continuous deployment from GitHub
Function Structure
- Function location:
/netlify/functions/process-meeting-background.ts
- The function is properly named with the
-background
suffix - I’ve configured it in
netlify.toml
as a background function
What I’ve tried
- I’ve configured the netlify.toml file with specific included_files and external_node_modules:
[build]
command = "npm run build"
publish = ".next"
[functions]
directory = "netlify/functions"
node_bundler = "esbuild"
external_node_modules = [
"@prisma/client",
"langchain",
"@langchain/textsplitters",
"p-limit"
]
# Specific configuration for the process-meeting-background function
[functions.process-meeting-background]
background = true
included_files = [
# Include all necessary source files from lib directory
"src/lib/**",
# Include database connection and models
"src/server/db.ts",
"src/server/db/**",
# Include Prisma schema and generated files
"prisma/schema.prisma",
"node_modules/.prisma/**",
# Include configuration files
"package.json",
".env",
".env.production"
]
-
Changed dynamic imports to static imports in the function file to avoid bundling issues.
-
Double-checked my function URL construction in the client code:
const backgroundFunctionUrl = "/.netlify/functions/process-meeting-background";
const url = new URL(backgroundFunctionUrl, process.env.NEXT_PUBLIC_APP_URL);
Error Logs
Here’s the error I’m seeing in the Netlify logs:
Mar 18, 12:46:25 PM: b742d06a INFO Triggering background function at: https://insightseek.vip/.netlify/functions/process-meeting-backgroundMar 18, 12:46:26 PM: 5c88ba87 Duration: 610 ms Memory Usage: 257 MBMar 18, 12:46:26 PM: b742d06a ERROR Background function error: 404 Not FoundMar 18, 12:46:26 PM: b742d06a ERROR Response body: <!DOCTYPE html><html lang="en" class="__variable_3a0388"><head><meta charSet="utf-8"/><meta name
Build Logs
I did encounter a warning during a previous deployment: “request body too large” when trying to upload the function, which I attempted to fix by being more selective with included_files
and external_node_modules
.
Questions
- Why is my function returning a 404 when it should be deployed?
- Is there an issue with how I’m configuring my background function in the netlify.toml file?
- Could there be an issue with the bundling process that’s preventing my function from being correctly deployed?
- Are there specific settings that might be blocking the function from being accessible?
Any guidance on troubleshooting this issue would be greatly appreciated. I’ve been trying to resolve this for a while and can’t figure out why the function can’t be reached despite following the documentation.