Deploying a file alongside a function fails (HTTP Error 502)

Hi everyone,

I have a question regarding Netlify’s lambda functions. I am trying to read a JSON file inside a lambda function, which are both in the same directory.

This is somewhat tricky, and has apparently been solved in this thread: How to deploy a directory along with a function? using the boilerplate provided here:

I set up my project in the same way the Github sample is set up, however, when the function is triggered a HTTP 502 error is returned immediately.

The function is working correctly when I use Netlify Dev on my local machine.

This is the URL, that triggers the error:

Did anyone already solve a similar problem to this? Thanks in advance for any advice.

PS: The function log does not show any errors. I am using zip-it-and-ship-it like in the Github project.

I just figured it out. I will reply to myself so others with the same problem can find this in the future.

I solved the problem by reading the JSON file using require(). This will lead Netlify to package the file with the function.

const content = require('./data.json');
1 Like