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,
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.
The folder name error is a real newbie’s mistake. We will go to hell for this. 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 !!!
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!
Thanks for reaching out, and welcome to the Netlify Forums. Can you please share more about your post? Are you encountering obstacles? If so, please share your netlify site URL as well as your functions folder.
@existo thanks for sharing, I will try it after I got solved another issue regarding build. I will create an issue but still do not know where to post a fresh one.