首页 > 解决方案 > 在 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

然而,这似乎没有任何作用。有谁知道错误可能在哪里?或者我应该在哪里寻找解决方案?我通常不在家处理这种东西,但我被迫使用它一段时间。任何帮助和建议将不胜感激!

标签: amazon-web-servicesnpm-installamazon-elastic-beanstalk

解决方案


这是 AWS 的权限问题。

要解决此问题,您必须执行以下步骤:

  1. 创建一个新文件 .npmrc
  2. 添加以下 unsafe-perm=true

这将允许写入文件。


推荐阅读