Understanding the `included_files` settings for functions

I guess this question might end up in the realm of Javascript rather than Netlify Functions but any help is welcome…

I’m trying to better understand how to access the files I added through the included_files functions settings.

I’ve read this topic (https://answers.netlify.com/t/netlify-toml-configuration-property-functions-included-files-must-be-an-object-error/38372_) but it does not get into the details of how to properly reference the files.

Assuming I have in my base directory (repo root) a json file called /data/test/one.json which I want to require/import in my function. Here are my settings:

[functions]
  directory = "functions"
  included_files = ["data/test/*"]

[dev]
 functions = "functions"

Note that I’m working locally with netlify dev and as the settings for functions in production and functions in dev uses a different syntax, I’m not even sure my included_files are available through netlify dev.

And here’s my function:

exports.handler = async function(event, context) {
  const data = require ('data/test/one.json')
  console.log(data)
  return {
    statusCode: 200,
    body: JSON.stringify(data)
  }
}

Whenever it’s invoked I get the error: “Cannot find module ‘data/test/one.json’\n” alongside a Require stack which does not include the directory I passed through included_files

Am I missing something?

Hey @regisphilibert,
To be honest, this all looks very reasonable to me! Just to make sure we’re not missing something small, could you please try included_files = ["./data/test/*"] and then require like this: require('./data/test/one.json)?