除非手动执行,否则 Elastic Beanstalk 上的“npm install”会失败

2023-12-03

我有一个带有 PHP 应用程序的 Elastic Beanstalk 环境。我只想跑npm install我的应用程序部署后。

node and npm都通过部署配置安装在服务器上。我定义了一个容器命令,只需 cd 到正确的目录,然后运行npm install, 但它always失败并出现相同的错误。

如果我手动执行npm install,一切都完美安装。

我该如何调试这个?

部署配置文件

commands:
    01_mkdir_webapp_dir:
      # use the test directive to create the directory
      # if the mkdir command fails the rest of this directive is ignored
      test: 'mkdir /home/webapp'
      command: 'ls -la /home/webapp'
    02_chown_webapp_dir:
      command: 'chown webapp:webapp /home/webapp'
    03_chmod_webapp_dir:
      command: 'chmod 700 /home/webapp'
    04_node_install:
        cwd: /tmp
        test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
        command: 'yum install -y nodejs --enablerepo=epel'
    05_npm_install:
        cwd: /tmp
        test: '[ ! -f /usr/bin/npm ] && echo "npm not installed"'
        command: 'curl -L http://npmjs.org/install.sh | sh'
    06_node_update:
        cwd: /tmp
        test: '[ ! -f /usr/bin/n ] && echo "node not updated"'
        command: 'npm install -g n && n stable'

# These commands will be run just before the application is started
container_commands:
    01_npm_build:
        cwd: '/var/app/ondeck/wp-content/themes/gift-certificates'
        command: 'npm install && npm run build'

tail of npm-debug.log

...

90557 silly lifecycle [email protected]~install: no script for install, continuing
90558 silly install [email protected] /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/imagemin-gifsicle-836840bb
90559 info lifecycle [email protected]~install: [email protected]
90560 silly lifecycle [email protected]~install: no script for install, continuing
90561 silly install [email protected] /var/app/ondeck/wp-content/themes/gift-certificates/node_modules/.staging/jpegtran-bin-6b358de8
90562 info lifecycle [email protected]~install: [email protected]
90563 silly rollbackFailedOptional Finishing
90564 silly runTopLevelLifecycles Starting
90565 silly runTopLevelLifecycles Finishing
90566 silly install printInstalled
90567 warn optional Skipping failed optional dependency /chokidar/fsevents:
90568 warn notsup Not compatible with your operating system or architecture: [email protected]
90569 verbose stack Error: [email protected] install: `node scripts/install.js`
90569 verbose stack spawn ENOENT
90569 verbose stack     at errnoException (child_process.js:1011:11)
90569 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:802:34)
90570 verbose pkgid [email protected]
90571 verbose cwd /var/app/ondeck/wp-content/themes/gift-certificates
90572 error Linux 4.4.15-25.57.amzn1.x86_64
90573 error argv "node" "/usr/local/bin/npm" "install"
90574 error node v6.6.0
90575 error npm  v3.10.3
90576 error file sh
90577 error code ELIFECYCLE
90578 error errno ENOENT
90579 error syscall spawn
90580 error [email protected] install: `node scripts/install.js`
90580 error spawn ENOENT
90581 error Failed at the [email protected] install script 'node scripts/install.js'.
90581 error Make sure you have the latest version of node.js and npm installed.
90581 error If you do, this is most likely a problem with the node-sass package,
90581 error not with npm itself.
90581 error Tell the author that this fails on your system:
90581 error     node scripts/install.js
90581 error You can get information on how to open an issue for this project with:
90581 error     npm bugs node-sass
90581 error Or if that isn't available, you can get their info via:
90581 error     npm owner ls node-sass
90581 error There is likely additional logging output above.
90582 verbose exit [ 1, true ]

tail of eb-commandprocessor.log

  ...

  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  +-- [email protected]
  `-- [email protected]
  `-- [email protected]
  `-- [email protected]

  npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
  npm WARN notsup Not compatible with your operating system or architecture: [email protected]
  npm ERR! Linux 4.4.15-25.57.amzn1.x86_64
  npm ERR! argv "node" "/usr/local/bin/npm" "install"
  npm ERR! node v6.6.0
  npm ERR! npm  v3.10.3

  npm ERR! Callback called more than once.
  npm ERR!
  npm ERR! If you need help, you may report this error at:
  npm ERR!     <https://github.com/npm/npm/issues>

  npm ERR! Please include the following file with any support request:
  npm ERR!     /var/app/ondeck/wp-content/themes/gift-certificates/npm-debug.log
   (ElasticBeanstalk::ExternalInvocationError)


[2016-09-20T17:38:57.831Z] ERROR [4286]  : Command CMD-AppDeploy failed!
[2016-09-20T17:38:57.837Z] INFO  [4286]  : Command processor returning results:
{"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"(TRUNCATED)...\nnpm ERR! If you need help, you may report this error at:\nnpm ERR!     <https://github.com/npm/npm/issues>\n\nnpm ERR! Please include the following file with any support request:\nnpm ERR!     /var/app/ondeck/wp-content/themes/gift-certificates/npm-debug.log. \ncontainer_command 01_npm_build in .ebextensions/deploy.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]}],"truncated":"true"}

对于在 PHP Elastic Beanstalk 实例上遇到此问题的其他人,以下是帮助我解决此问题的方法:

1) 如果您在 Amazon Linux 实例上运行,请执行以下操作yum install nodejs会给你一个超级旧的版本,很可能与很多东西不兼容。我必须添加一个脚本到我的.ebextensionsdir 并从我的配置之一执行它以安装 Nodejs 的更新版本。这是该脚本的副本:

#!/bin/bash

hash_file="/tmp/nodejshash"

check_if_npm_packages_has_to_be_installed () {
    if [ -f $hash_file ]; then
        check_if_same_hash
    else
        return 0
    fi
}

check_if_same_hash () {
    hash_new="$(md5sum .ebextensions/bin/install-nodejs.sh 2> /dev/null | cut -d ' ' -f 1)"
    hash_current="$(cat "$hash_file" 2> /dev/null | cut -d ' ' -f 1)"

    if [ $hash_new == $hash_current ]; then
        return 1
    else
        return 0
    fi
}

install_node () {
    if hash nodejs 2> /dev/null; then
        echo 'nodejs install, add more processing if needed' > /dev/null
    else
        curl -sL https://rpm.nodesource.com/setup_6.x | bash -
        yum install -y nodejs
    fi
}

install_npm_packages () {
    npm install -g bower
    npm install -g gulp
}

update_current_hash () {
    echo $hash_new > $hash_file
}

install_node

if check_if_npm_packages_has_to_be_installed; then
    install_npm_packages
    update_current_hash
fi

2) 如果您默认使用微型实例,node-sass包花费了很长时间来构建并最终超时。我将实例大小增加到t2.small为了克服这个问题。

希望这可以帮助其他人。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

除非手动执行,否则 Elastic Beanstalk 上的“npm install”会失败 的相关文章

  • 将 PDF 转换为 600dpi 的 TIFF 和 jpg 96 dpi

    我想使用 ImageMagick 从 Python 脚本将 pdf 转换为 600 dpi 的 tiff 和 96 dpi 的 jpg 我使用 imagemagick 命令行完成了这项任务 但我想使用python中的Imagemagick将
  • NPTL 和 POSIX 线程有什么区别?

    NPTL 和 POSIX 线程之间的基本区别是什么 这两者是如何演变的 POSIX 线程 pthread 不是一个实现 它是几个函数的 API 规范 纸上的标准 英文 其名称以pthread 以及定义在
  • libxmljs 的替代品 [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 目标 使用 Node js 访问网页 使用 xpath 语法操作 DOM 并打印新的 DOM libxm
  • 如何设置上传的文件名?

    By using multer I made it to request image file like this 这个文件存储在我设置的 上传 文件夹中 我的代码如下 var multer require multer var uploa
  • Node.js 重写 toString

    我试图覆盖我的对象的默认 toString 方法 这是代码和问题 function test this code 0 later on I will set these this name test prototype toString f
  • editMessageReplyMarkup 方法删除内联键盘

    我正在使用 node js 制作一个电报机器人node telegram bot api图书馆 我回答callback query并想更换我的内联键盘 下面的代码显示了我如何尝试使用此方法 但是当我在电报中点击键盘时 它就消失了 bot o
  • 如何在apache 2.4.6上安装apxs模块

    我刚刚用过apt get update我的 apache 已更新为2 4 6 我想安装 apxs 来编译模块 但收到此错误 The following packages have unmet dependencies apache2 pre
  • 使用 sh 运行 bash 脚本

    我有 bash 脚本 它需要 bash 另一个人尝试运行它 sh script name sh 它失败了 因为 sh 是他的发行版中 dash 的符号链接 ls la bin sh lrwxrwxrwx 1 root root 4 Aug
  • 根据特定字符获取整个字符串或子字符串

    我有一个包含 MIME 类型的字符串 例如application json 现在我想将其与实际的 HTTP 标头进行比较 在本例中content type 如果标头包含 MIME 类型 那么就很简单 if mimeType contentT
  • 为什么我会收到 ElasticBeanstalk::ExternalInitationError?

    我的应用程序基于 RubyOnRails 构建 并使用乘客部署为弹性 beanstalk 应用程序 我尝试向 nginx 服务器添加标头并重新启动它 这是我的配置文件 是 aws elastic beanstalk 中 ebextensio
  • 下载中带有文件名的 NodeJS sendFile

    我尝试使用以下代码将文件发送给客户端 router get get myfile function req res next res sendFile other file name dat 它工作正常 但当用户从以下网址下载此文件时我需要
  • jpegtran 优化而不更改文件名

    我需要优化一些图像 但不更改它们的名称 jpegtran copy none optimize image jpg gt image jpg 但是 这似乎创建了 0 的文件大小 当我对不同的文件名执行此操作时 大小仍然完全相同 怎么样 jp
  • Nodejs Express中间件函数返回值

    我正在使用 NodeJS 和 Express 我有以下路线 中间件功能是Mobile 如果我不使用 return next 在 isMobile 函数中 应用程序会卡住 因为 NodeJS 不会移至下一个函数 但我需要 isMobile 函
  • 在 Node.js 中,setTimeout() 会阻止事件循环吗?

    如果我有一个简单的 setTimeout 函数 并将其设置为 10 秒 整个服务器在那10秒内就死机了 这是真的 这就是我听到的 答案是no 你的链接是什么Node js 如何重新创建 setTimeout 函数而不阻塞事件循环 https
  • 如何授予 apache 使用 NTFS 分区上的目录的权限?

    我在一台带有 20GB 硬盘的旧机器上运行 Linux Lubutu 12 10 我有一个 1 TB 外部硬盘 上面有一个 NTFS 分区 在该分区上 有一个 www 目录 用于保存我的网页内容 它在启动时自动安装为 media t515
  • 为arm构建WebRTC

    我想为我的带有arm926ej s处理器的小机器构建webrtc 安装 depot tools 后 我执行了以下步骤 gclient config http webrtc googlecode com svn trunk gclient s
  • 在我的 index.php 中加载 CSS 和 JS 等资源时出现错误 403

    我使用的是 Linux Elementary OS 并在 opt 中安装了 lampp My CSS and JS won t load When I inspect my page through browser The console
  • 如何配置 Google 计算引擎以对 Nodejs 服务器使用 HTTPS?

    我想使用 https SSL 在 google 计算引擎中运行 nodejs 和 socket io 服务器 我安装了自签名证书https cloud google com compute docs load balancing http
  • jq中如何分组?

    这是 json 文档 name bucket1 clusterName cluster1 name bucket2 clusterName cluster1 name bucket3 clusterName cluster2 name bu
  • 流星内存不足

    我正在使用流星来制作报废引擎 我必须执行一个 HTTP GET 请求 这会向我发送一个 xml 但这个 xml 大于 400 ko 我得到一个异常 内存不足 result Meteor http get http SomeUrl com 致

随机推荐