Functions:build and included_files

I’m having trouble migrating from the netlify-lambda CLI to netlify-cli for lambda functions. I like the zip-it-and-ship-it model for bundling functions vs. the mysteries of webpack. Bravo for embracing this instead!

I’ve read every single support article about the included_files feature but have never once been able to get it to work. For example, I’m trying to include the file openapi.yaml:

  included_files = ["./openapi.yaml"]

Which resides next to the javascript function I’ve implemented. After running netlify functions:build --src ./myfunctions/source, I inspect the resulting zip file and there is no openapi.yaml file in it.

If in my javascript file I were to reference it like such:


which will of course cause an error because it’s a YAML file, the file is included. So how does one actually use the included_files correctly, when you have a source tree like this:

├── myfunctions
│   └── source
│       ├── main.js
│       └── openapi.yaml
├── netlify
│   └── functions
└── netlify.toml


Included files works relative to the base folder not the functions folder.

Thank you for the reply. Even when I change netlify.toml like this:

  functions = "netlify/functions"

  node_bundler = "esbuild"
  included_files = ["./netlify/functions/main/openapi.yaml"]

and run netlify functions:build --src netlify/functions/main, I don’t see it included in the zip file:

netlify functions:build --src netlify/functions/main
◈ Building functions
◈ Functions built to  /Users/tony/dev/projects/fehguy/netlify-api/netlify/functions

What am I missing? repo updated here:

OK I now understand what you meant. The file location for included_files should reference files relative to the project root (folder where netlify.toml lives), and the scripts themselves should assume that the cwd is the project root directory as well.

So having this:

├── netlify
│   └── functions
│       └── main
│           ├── main.js
│           └── package.json
├── netlify.toml
├── package.json
└── src
    └── openapi.yaml

with netlify.toml like this:

  functions = "netlify/functions"

  node_bundler = "esbuild"
  included_files = ["./src/openapi.yaml"]

Will allow the file to be read in my javascript file as this:

const data = fs.readFileSync("./src/openapi.yaml", "utf-8");

Thanks again for the help! I’m all set.