netlify functions: Build and Deploy Functions
netlify functions:build bundles serverless functions and netlify functions:invoke calls one locally for testing.
Functions ship as part of a deploy, but the functions subcommands let you build and test them in isolation in a pipeline before the real deploy.
What it does
netlify functions:build compiles the source functions into deployable bundles in the configured functions directory. netlify functions:serve runs them locally, and netlify functions:invoke NAME sends a test event to one. The main netlify deploy picks up the built functions automatically.
Common usage
# bundle functions to a directory
netlify functions:build --functions netlify/functions --src functions/src
# invoke one locally with a JSON payload
netlify functions:invoke hello --payload '{"name":"ci"}' --no-identity
# deploy site + functions together
netlify deploy --prod --dir=dist --functions netlify/functions --auth "$NETLIFY_AUTH_TOKEN"Options
| Command / flag | What it does |
|---|---|
| functions:build | Bundle functions to the output directory |
| functions:invoke <name> | Call a function locally with a test event |
| --functions <dir> | Output directory for built functions |
| --payload <json> | Body to send to functions:invoke |
| functions:serve | Run functions on a local dev server |
In CI
Run functions:build (or netlify build) before deploy so a bundling failure surfaces as its own step. Esbuild is the default bundler; native or unusual dependencies sometimes need to be marked external in netlify.toml.
Common errors in CI
"Bundling of function ... failed" with an esbuild "Could not resolve" line means a dependency is missing or needs external_node_modules in netlify.toml. "Error: Functions folder not found" means --functions points at a path that does not exist. Auth/site errors are the same as netlify deploy: set NETLIFY_AUTH_TOKEN.