amazon-web-services - 在 Elastic Beanstalk 上安装 Sharp
问题描述
我对 AWS 比较陌生。我在 Elastic Beanstalk 上运行 Node.JS 应用程序,一切正常。但是,因为我需要做一些图像处理,所以我决定添加 Puppeteer 和 Sharp。
但是,AWS 上的安装失败并且应用程序崩溃。日志显示以下内容:
sharp@0.21.3 install /tmp/deployment/application/node_modules/sharp
(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
ERR! sharp EACCES: permission denied, mkdir '/tmp/.npm/_libvips'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/sharp/build'
gyp ERR! System Linux 4.14.97-74.72.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/sharp
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.21.3 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sharp@0.21.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我真的不熟悉 Elastic Beanstalk,但这似乎是一个访问限制错误。经过一番搜索,我找到了一个可能的解决方案:将以下代码添加为 .extension 文件。
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm
然而,这似乎没有任何作用。有谁知道错误可能在哪里?或者我应该在哪里寻找解决方案?我通常不在家处理这种东西,但我被迫使用它一段时间。任何帮助和建议将不胜感激!
解决方案
这是 AWS 的权限问题。
要解决此问题,您必须执行以下步骤:
- 创建一个新文件 .npmrc
- 添加以下 unsafe-perm=true
这将允许写入文件。
推荐阅读
- ruby-on-rails - 将 ruby 版本从 1.9.3 升级到 2.0.0 时 rspec 失败
- algorithm - 跳转搜索算法:伪代码错误
- php - 根据产品 ID 向 WooCommerce“我的帐户”订单添加操作按钮
- python - pyspark,通过别名按数组特定属性分组
- excel - 获取 Office.js excel 中更改的单元格“valueBefore”
- git - 是否可以在没有本地仓库的情况下将一些文件附加到远程仓库?
- sql-server - 在变量中查找一个单词并渲染 1 else 0
- android - 谷歌地图或一些自定义地图反应原生
- excel - 如何将标题限制在我的工作簿中?
- css - 使用 Angular CLI 动态加载 CSS