title: "Runtime.ImportModuleError" trying to access npm package in an AWS lambda function using layers
body: <p>I'd like to use the npm package "request" in an AWS lambda function.</p>
  
  <p>I'm trying to follow the procedure outlined in this article here: <a href="https://medium.com/@anjanava.biswas/nodejs-runtime-environment-with-aws-lambda-layers-f3914613e20e" rel="noreferrer">https://medium.com/@anjanava.biswas/nodejs-runtime-environment-with-aws-lambda-layers-f3914613e20e</a></p>
  
  <p>I've created a directory structure like this:</p>
  
  <pre><code>nodejs
  │   package-lock.json
  │   package.json
  └───node_modules
  </code></pre>
  
  <p>My package.json looks like this:</p>
  
  <pre><code>{
    "name": "my-package-name",
    "version": "1.0.0",
    "description": "whatever",
    "author": "My Name",
    "license": "MIT",
    "dependencies": {
      "request": "^2.88.0"
    }
  }
  </code></pre>
  
  <p>As far as I can tell from the article, all I should have to do with the above is run <code>npm i</code>, zip up the directory, upload it as a layer, and add the layer to my lambda function.</p>
  
  <p><a href="https://i.stack.imgur.com/UaJFk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UaJFk.png" alt="screenshot"></a></p>
  
  <p>I've done all of that, but all that I get when I try to test my function is this:</p>
  
  <pre><code>{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'request'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "trace": [
      "Runtime.ImportModuleError: Error: Cannot find module 'request'",
      "Require stack:",
      ...
  </code></pre>
  
  <p>...as if the layer had never been added. The error is exactly the same whether the layer is added or not. If there's some sort of permissions issue that needs to be resolved, there's nothing in the article that indicates that.</p>
  
  <p>I've tried a few different things, like whether or not my .zip file contains the top-level directory "nodejs" or just its contents. I've tried adding <code>"main": "index.js",</code> to my <code>package.json</code>, with an <code>index.js</code> file like this:</p>
  
  <pre><code>export.modules.request = require('request');
  </code></pre>
  
  <p>...all to no avail.</p>
  
  <p>What am I missing?</p>