title: AWS Lambda : module initialization error
body: <p>I create a Lambda function on AWS with library call <a href="https://github.com/mscdex/mmmagic" rel="nofollow noreferrer">mmmagic</a> to check the mimeType from uploaded S3 file event. Everything works fine on my machine with mock test event. I'm sure that I upload all the dependency inside <code>node_modules</code> to Lambda.</p>
  
  <p><strong>This is an error message from Lambda  :</strong></p>
  
  <pre><code>module initialization error: Error
  at Error (native)
  at Object.Module._extensions..node (module.js:597:18)
  at Module.load (module.js:487:32)
  at tryModuleLoad (module.js:446:12)
  at Function.Module._load (module.js:438:3)
  at Module.require (module.js:497:17)
  at require (internal/module.js:20:19)
  at Object.&lt;anonymous&gt; 
  (/var/task/node_modules/mmmagic/lib/index.js:3:13)
  at Module._compile (module.js:570:32)
  at Object.Module._extensions..js (module.js:579:10)
  </code></pre>
  
  <p><strong>Here is my code :</strong>  </p>
  
  <pre><code>const aws = require('aws-sdk')
  const mmagic = require('mmmagic');
  const s3 = new aws.S3();
  
  exports.handler = (event, context, callback) =&gt; {
      const params = {
          Bucket: event.Records[0].s3.bucket.name,
          Key: event.Records[0].s3.object.key
      }
      s3.getObject(params, (err, data) =&gt; {
          if (err) console.log(err, err.stack) // an error occurred
          else {
              var magic = new mmagic.Magic();
              magic.detect(data.Body, function (err, result) {
                  if (err) {
                      console.log('Error when try getting mime type:' + err) // logherer
                  } else {
                      // do something
                  }
              }
          });
      }
  })
  </code></pre>
  
  <p>}</p>
  
  <p><strong>package.json</strong></p>
  
  <pre><code>{
      "aws-sdk": "^2.188.0",
      "mmmagic": "^0.4.6"
  }
  </code></pre>