node.js - Testing module that requires a module from a layer in AWS Lambda
问题描述
So, I am using Layers in my Serverless Framework Node JS project. I add all commonly used npm packages to a layer because I don't want every Lambda function to have huge packages.
The problem is that when running unit tests (locally), it can't find these modules.
Is there any way to handle this problem?
解决方案
尝试以下操作:
- 将 package.json 文件添加到您的项目中,其中包含所有依赖项
- 安装依赖项,因此您将在本地拥有它们
- 在无服务器框架中使用Exclude选项,这样最终的包将不包含 node_modules 目录:
package:
exclude:
- node_modules/**
推荐阅读
- .net - .NET 和 .NET Core 的 dotnet.exe 命令
- python - 将文本搜索添加到基于内容的图像检索 (convnet)
- json - reduce 函数正在打印一个空字典 [:]
- sql - 汇总不同仓库位置的库存值
- node.js - TCP 数据包中的禁止字符
- android-studio - 如何从 Android Studio 的“分析->检查代码”中排除某些目录?
- android - 如何通过 android 中的数据绑定将 onTextChanged 侦听器添加到包含布局 xml
- xcode - React Native iOS - 安装 Firebase pod 后出现 addNetworkingHandler 和 NetInfo 不变违规错误。我该如何修复它们?
- bash - bash 从 ping 命令中获取 ms
- html - 意外的不透明度行为