I’m experiencing a 404 error when trying to access a Netlify Function from my Nuxt 3 application. The function is properly set up in the netlify/functions directory but returns a 404 Not Found error when called.
[build]
command = "npm run generate"
publish = "dist"
functions = "netlify/functions"
[functions]
directory = "netlify/functions"
node_bundler = "esbuild"
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
force = true
headers = {Access-Control-Allow-Origin = "*"}
Error:
When making a POST request to /.netlify/functions/email, I get a 404 Not Found error. The function code is correct and the directory structure follows Netlify’s documentation.
The function directory is correctly set in netlify.toml
The function file is in the correct location
The build command is correct
The redirects are properly configured
Hi, thanks for the response. Yes, I’m using npm locally. I haven’t tried netlify dev yet - should I install the Netlify CLI and test that first?
Currently when I try to access the function endpoint at /.netlify/functions/email I get a 404 error. The function exists in the correct location at netlify/functions/email/email.ts and I have the proper netlify.toml configuration:
Thanks for the follow-up @codemonkeynorth. I’ve identified the issue - I’m trying to use a Netlify Function for email handling, but I’m getting 404 errors when accessing /.netlify/functions/email in production. Here’s my current setup:
[build]
command = "npm run generate"
publish = "dist"
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
force = true
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
I get a Edge Functions error during deployment but that seems to be a red herring - I don’t actually need Edge Functions for this use case, just regular Netlify Functions.
The main issue is that the function endpoint returns 404 in production despite being in the correct location. I’ve verified that:
The function files are being included in the deployment
The function dependencies (Resend) are properly specified in the function’s package.json
The RESEND_API_KEY environment variable is set in Netlify
Could this be related to:
Function bundling configuration?
The way I’m deploying from StackBlitz’s WebContainer environment?
Or do I need additional configuration to expose the function endpoint?
This feature requires either continuous deployment or manual deploys with Netlify CLI. If you’re not using Netlify CLI, we recommend connecting a Git repository for continuous deployment.
I can see it’s a manual deploy, are you using Netlify CLI or did you use Netlify’s Drag and Drop?
If you’re using Netlify CLI, this section should help:
You may need to add under [build] within the netlify.toml the following:
Looking at the latest deploy logs, in the Deploy file browser, I see that the netlify.toml file isn’t included which could be the issue. The netlify.toml file should be in the root of the project directory.