我试图上传函数的图像裁剪依赖作为一个aws。它在我的本地机器(node v14.17.3)上工作得很好,但是当将它作为lambda触发时,会发生以下错误。
"errorType":
"Error"
"errorMessage":
"\nSomething went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-linux-x64.node'\nRequire stack:\n- /var/task/node_modules/sharp/lib/sharp.js\n- /var/task/node_modules/sharp/lib/constructor.js\n- /var/task/node_modules/sharp/lib/index.js\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js\n\nPossible solutions:\n- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"\n- Install for the current runtime: \"npm install --platform=linux --arch=x64 sharp\"\n- Consult the installation documentation: https://sharp.pixelplumbing.com/install"
"stack":
"Error: "
"Something went wrong installing the \"sharp\" module"
""
"Cannot find module '../build/Release/sharp-linux-x64.node'"
"Require stack:"
"- /var/task/node_modules/sharp/lib/sharp.js"
"- /var/task/node_modules/sharp/lib/constructor.js"
"- /var/task/node_modules/sharp/lib/index.js"
"- /var/task/index.js"
"- /var/runtime/UserFunction.js"
"- /var/runtime/index.js"
""
"Possible solutions:"
"- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\""
"- Install for the current runtime: \"npm install --platform=linux --arch=x64 sharp\""
"- Consult the installation documentation: https://sharp.pixelplumbing.com/install"
" at Object.<anonymous> (/var/task/node_modules/sharp/lib/sharp.js:30:9)"
" at Module._compile (internal/modules/cjs/loader.js:1085:14)"
" js文件名为index.js,我已经压缩了下面的所有文件。所有文件权限如下:
-rw-r--r-- 1 ***** staff 1379 Dec 26 12:22 index.js
-rw-r--r-- 1 ***** staff 280 Dec 26 12:59 package.json
drwxr-xr-x 6 ***** staff 192 Dec 26 13:08 ..
-rw-r--r-- 1 ***** staff 44154 Dec 26 13:31 package-lock.json
drwxr-xr-x 69 ***** staff 2208 Dec 26 13:31 node_modules我不知道如何按照错误建议来调试这个问题,因为图像裁剪器在我的本地机器上工作得很好。图像裁剪器版本是:
"node_modules/sharp": {
"version": "0.29.3",
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.29.3.tgz",
....有什么建议吗?我哪里出错了?
发布于 2022-03-01 10:10:58
要在MAC上修复它,请尝试以下解决方案:
npm install --platform=linux --arch=x64 sharp对我起作用了。
发布于 2022-10-11 14:37:11
我建议使用一个层,更容易配置和部署。在AWS控制台上,您可以部署此层- https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/create/app?applicationId=arn:aws:serverlessrepo:us-east-1:987481058235:applications/nodejs-sharp-lambda-layer。
如果该URL不起作用,请导航到控制台-> Create Function -> Browse Serveless App ->搜索"Sharp",选择“nodejs-sharp层”。
在您的lambda函数上部署层->,选择该层。
我目前有两个层,一个用于我所有的其他node_modules (axios,等等)。

发布于 2022-08-24 18:13:15
如果任何包都依赖于Linux平台,则会出现此问题。为了解决这个问题,首先使用下面的命令,它将删除现有的Sharp包-
rm -rf node_modules/sharp之后,使用下面提到的命令安装Linux平台的Sharp版本
npm install --arch=x64 --platform=linux --target=16x sharp我希望这会有所帮助。
https://stackoverflow.com/questions/70487565
复制相似问题