lambda找不到我的node_modules [英] lambda not finding my node_modules

查看:74
本文介绍了lambda找不到我的node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lambda上传node_modules,但出现找不到模块" 错误.

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

我已经用

var async = require('async');

我已经手动将 node_modules/async 文件夹复制到发行版中-然后将node_modules文件夹与hello world js文件一起复制.

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.

我用我的照片调整器lambda做一个非常相似的事情,该照片也包含节点模块,并且可以工作.我做错了什么?

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?

推荐答案

zip文件的结构很重要.假设我有一个名为 foo.js 的文件中包含的javascript函数,该文件与其他节点模块具有依赖性.

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>

然后我创建一个名为 foo.zip 的zip文件,其结构如下:

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
<...>

确保您的zip文件具有这种结构,并且应该没问题.

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

这篇关于lambda找不到我的node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆