从 windows 部署 sls 代码后得到 "module initialization error"

getting "module initialization error" after deploying sls code from windows

我正在我的办公室部署 lambda 函数,我有 ubuntu 操作系统。当我部署我的无服务器代码时,它工作正常,我可以毫无问题地访问 lambda api。但是当我在我有 windows 操作系统的家用机器上部署相同的代码时,它在访问 lambda api ("Note- There is no issues while deploying it, issue comes when i access the lambda API after deploying it from windows machine") 时显示错误 "module initialization error"。 =15=]

我调试了这个问题,我发现这个问题与 "bcrypt" 包有关。在日志中我看到,当代码执行到达我导入 "bcrypt" 模块的文件时,它会抛出错误。我不知道为什么它在 2 个不同的操作系统上仅针对 bcrypt 显示两种不同的行为。

 "dependencies": {
    "@serverless/fdk": "^0.7.1",
    "bcrypt": "^3.0.6",
    "jsonwebtoken": "^8.5.1",
    "mysql": "^2.17.1",
    "serverless-http": "^2.0.2"

myOwnFunction 的日志

module initialization error
Error
2019-06-08 09:25:06.043 (+05:30)        33f9015c-c9f0-43a5-8c4a-1fc617ad955d    inside OwnerModel

在我的代码中,当代码执行到下一行时

import bcrypt from  'bcrypt';

显示模块初始化错误

我希望执行 lambda api,即使它是在 windows 机器的帮助下部署的。

您需要使用特定的 NodeJS 版本在 Amazon Linux 上编译 bcrypt 模块,然后压缩并部署它。

或者,我建议使用 bcryptjs