Home
Support Forums

We don't understand how the included_files [functions] parameter works

We have read this: How to Include Files in Netlify Serverless Functions

And this: File-based configuration | Netlify Docs

But we are not able to make it work.

Here is a simple example: https://github.com/juanmiguelguerrero/test-included-files-function

We want “./src/data.json” to be accessible in our lambda function “test.js”.

In netlify-cli dev environment, we always get the same error: Could not resolve "./src/data.json"

Could someone modify our example to make it work correctly???

Thanks

Netlify functions can’t access files outside of its own folder. If you put the json file in your functions’ folder, it should work.

Thanks Tom,

I’m sorry but I’m not satisfied with your answer.

We already know that a function cannot access files outside of its folder…

Have you read the first attached article?

I copy literally:

One option is to tell our build system the paths of any additional files that should be included in the function deployment. This can be done in the netlify.toml configuration file using the included_files property of the functions block,

(extract from How to Include Files in Netlify Serverless Functions)

Reading this I understand that by setting the included_files parameter the system will copy the selected files to the function folder automatically in the function deployment.

I copy the end of the article (literally):

You can include any type of file in your serverless functions, even if you reference them using dynamic expressions. You can add these files manually in your configuration file...

We think the author (@eduardoboucas) explains it clearly. Modifying the netlify.toml configuration you can automate the adding of any file in the deploy of your function.

Right, just making sure you’re setting things up correctly…You’re trying to load the file as if it’s within the functions folder though, but it’s not. Try ../src/data.json instead of ./src/data.json

Also, your folder is named scr instead of src, so you’ll need to fix that, obviously.

Yes !!!

Now the example is corrected and running: https://sharp-lichterman-df15d5.netlify.app/

The folder name error is a real newbie’s mistake. We will go to hell for this. :scream: Thanks.

Taking the root directory as the main directory instead of the function folder is something you might want to include in the documentation. We had understood that everything happened inside the folder where the functions are hosted.

Thank you very much for your help.

This feature is very important for us because it helps us to simplify the deployment of on-demand builder functions. That’s great and simple !!!

Thanks Tom.

Taking the root directory as the main directory instead of the function folder is something you might want to include in the documentation.

Well… You’re trying to load the file from within the function, which lives inside the functions folder. So to reach the data file, you have to go back to root first, hence the ../.

If that’s the case, I’m screwed haha. Glad you’ve got it working though!

1 Like