1

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?

4

2 回答 2

0

尝试以下操作:

  1. 将 package.json 文件添加到您的项目中,其中包含所有依赖项
  2. 安装依赖项,因此您将在本地拥有它们
  3. 在无服务器框架中使用Exclude选项,这样最终的包将不包含 node_modules 目录:
package:
  exclude:
    - node_modules/**
于 2019-10-30T15:28:09.320 回答
0

Bar 的回答很好,但我也认为我可以使用 --save-dev 标志安装所有依赖项,就是这样!

于 2019-10-30T21:40:59.067 回答