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:
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: function-deploy-test/package.json at master · netlify/function-deploy-test · GitHub. From there, you should be able access your file like: function-deploy-test/zipped-function.js at master · netlify/function-deploy-test · GitHub.

Let me know if that helps.