Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lambda not finding my node_modules

I'm trying to upload node_modules with my lambda but I'm getting "Cannot find module" error.

I've set up a real simple hello world js file with

var async = require('async');

And I have manually copied over a node_modules/async folder into the distribution - and I copy up the node_modules folder along with the hello world js file.

I do a very similar thing with my photo resizer lambda which takes node modules as well and that works. What's different that I'm doing wrong?

like image 701
MonkeyBonkey Avatar asked Sep 03 '25 04:09

MonkeyBonkey


1 Answers

The structure of the zip file is important. Let's say I have a javascript function contained in a file called foo.js that has dependencies on other node modules.

In my development environment, I would have a structure like this:

devdir/
    foo/
        foo.js
        node_modules/
            <the nodejs modules>

I then create a zip file called foo.zip structured like this:

$ unzip -vl foo.zip 
Archive:  foo.zip
 Length   Method    Size  Ratio   Date   Time   CRC-32    Name
 -------  ------  ------- -----   ----   ----   ------    ----
       0  Defl:N        0   0%  08-05-15 14:44  00000000  ./
    3047  Defl:N      981  68%  08-05-15 14:25  06e3e178 foo.js
       0  Defl:N        0   0%  08-03-15 13:37  00000000  node_modules/
       0  Defl:N        0   0%  08-03-15 13:37  00000000 node_modules/.bin/
     597  Defl:N      301  50%  03-05-15 14:29  9b0c2ba2  node_modules/.bin/uuid
       0  Defl:N        0   0%  07-16-15 08:32  00000000  node_modules/async/
    3454  Defl:N     1537  56%  06-28-15 18:37  967a5404  node_modules/async/CHANGELOG.md
<...>

Make sure your zip file is structured like this and you should be ok.

like image 193
garnaat Avatar answered Sep 05 '25 01:09

garnaat