doapp-ryanp / serverless-plugin-browserify

Speed up your node based lambda's
MIT License
33 stars 4 forks source link

module initialization error: Error happens only on Lambda #11

Open faizhasim opened 7 years ago

faizhasim commented 7 years ago

I am requiring a module [provision-dynamodb]() in my serverless project (in which I'm one of the authors, so I can make changes to that module, if needed). Execution in lambda fails.

This is my lambda function:

const processConfigTables = require('provision-dynamodb');

export const hello = async (event: Object, context: Object, callback: Function) : any => {
  try {
    const result = await processConfigTables([{
      "name":"test-table",
      "readStrategy": {
        "name":"capacity-ratio",
        "upperThresholdRatio":0.8,
        "lowerThresholdRatio":0.15,
        "incrementRatio":3,
        "decrementRatio":0.8,
        "lowerBoundUnit":1,
        "upperBoundUnit":28},
      "writeStrategy": {
        "name":"capacity-ratio",
        "upperThresholdRatio":0.8,
        "lowerThresholdRatio":0.15,
        "incrementRatio":3,
        "decrementRatio":0.8,
        "lowerBoundUnit":1,
        "upperBoundUnit":28
      }
    }]);
    console.log('result = ', result);

    const response = {
      statusCode: 200,
      body: JSON.stringify({ok: true}),
    };

    return callback(null, response);
  } catch (err) {
    console.error('err', err);
    return callback(null, {
      statusCode: 500,
      body: JSON.stringify(err),
    });
  }
};

I got this error:

module initialization error: Error
    at Error (native)
    at Object.fs.readdirSync (fs.js:808:18)
    at Object.<anonymous> (/var/task/handler.js:3177:4)
    at Object.96.../package.json (/var/task/handler.js:3197:4)
    at s (/var/task/handler.js:1:682)
    at /var/task/handler.js:1:733
    at Object.102.nconf (/var/task/handler.js:4220:142)
    at s (/var/task/handler.js:1:682)
    at /var/task/handler.js:1:733
    at Object.105../config (/var/task/handler.js:4229:519)
faizhasim commented 7 years ago

I rewrote the code in ES5, supported natively by node 4.3 and remove babelify transformation. I still run into the same problem.

If I totally remove browserfiy, it works fine.

const processConfigTables = require('provision-dynamodb');

module.exports.hello = (event, context, callback) => {
  processConfigTables([{
    "name":"test-table",
    "readStrategy": {
      "name":"capacity-ratio",
      "upperThresholdRatio":0.8,
      "lowerThresholdRatio":0.15,
      "incrementRatio":3,
      "decrementRatio":0.8,
      "lowerBoundUnit":1,
      "upperBoundUnit":28},
    "writeStrategy": {
      "name":"capacity-ratio",
      "upperThresholdRatio":0.8,
      "lowerThresholdRatio":0.15,
      "incrementRatio":3,
      "decrementRatio":0.8,
      "lowerBoundUnit":1,
      "upperBoundUnit":28
    }
  }]).then(result => {
    const response = {
      statusCode: 200,
      body: JSON.stringify({ok: true}),
    };

    return callback(null, response);
  }).catch(err => {
    return callback(null, {
      statusCode: 500,
      body: JSON.stringify(err),
    });
  });
};