2

我遵循 AWS 研讨会 ( https://amplify-workshop.go-aws.com/70_generating_thumbnails/10_creating_a_photo_processor_lambda.html )通过 aws-amplify CLI 创建了一个 lambda 函数。似乎某个地方的 Node.js 版本冲突存在问题。

我相信锐利的库是问题所在,所以我尝试将版本更改为最新版本,看看是否会做任何事情,但它并没有解决问题。

CloudWatch 错误日志:

module initialization error: Error
was compiled against a different Node.js version using
NODE_MODULE_VERSION 67. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Object.Module._extensions..node (module.js:681:18)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:10:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)

我相信有一个简单的解决方法,但我不确定问题的根源在哪里。谢谢你。

4

3 回答 3

3

看起来您已经构建了node_modules使用 lambda 不兼容版本的Node.js. Lambda 仅支持Node.js 6.10 和 8.10。

尝试将本地节点版本更改为8.10、删除node_modules、、npm install捆绑文件夹,包括node_modules并上传到 lambda。这应该有效。

于 2019-01-22T01:24:38.987 回答
2

安装 sharp 时使用您的 aws lambda 节点版本。

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=10.4.1 sharp
于 2020-01-07T15:00:32.747 回答
1

以下对我有用:

npm_config_arch=x64 npm_config_platform=linux npm install sharp

由于某种原因,争论不起作用。

于 2021-08-23T16:02:08.090 回答