ENONET no such file... error when want to read a file

I am trying to read a file using readFileSync, but I get ENONET no such file or directory… error

my website structure:

I tested 4 ways but none of them worked.
here is 4 ways(hello.js):

const fs = require('fs');
const path = require('path');

const way1 = fs.existsSync('./data.txt'); // false
const way2 = fs.existsSync(path.join(__dirname, 'data.txt')); // false
const way3 = fs.existsSync(('var/task/src/data.txt')); // false

    const fileName = './data.txt';
    const resolved = (process.env.LAMBDA_TASK_ROOT)? path.resolve(process.env.LAMBDA_TASK_ROOT, fileName):path.resolve(__dirname, fileName);
    const way4 = fs.existsSync(resolved); // false

    exports.handler = function(event, context, callback) {
      callback(null, {
        statusCode: 200,
        body: JSON.stringify({
          way1, way2, way3, way4

the result is false for all 4 ways.

hi there, does this work locally?

@perry To test it locally I installed netlify-lambda module, then I used netlify-lambda serve lambda command. then I opened http://localhost:9000/.netlify/functions/hello and the result was the same, 4 falses

If you don’t require a file, netlify-lambda will not bundle it. You’ll want to self-zip your function like this: https://github.com/netlify/function-deploy-test/blob/master/package.json#L17. From there, you should be able access your file like: https://github.com/netlify/function-deploy-test/blob/master/lambda/zipped-function/zipped-function.js#L6-L8.

Let me know if that helps.