将 NodeJS 部署到 Elastic Beanstalk 时出现 NPM 错误

Posted

技术标签:

【中文标题】将 NodeJS 部署到 Elastic Beanstalk 时出现 NPM 错误【英文标题】:NPM error when deploying NodeJS to Elastic Beanstalk 【发布时间】:2016-03-09 04:15:59 【问题描述】:

我收到以下错误:

 5065 verbose linkBins sse4_crc32@4.1.1
5066 verbose linkMans sse4_crc32@4.1.1
5067 verbose rebuildBundles sse4_crc32@4.1.1
5068 verbose rebuildBundles [ 'bindings', 'nan' ]
5069 info install sse4_crc32@4.1.1
5070 verbose unsafe-perm in lifecycle false
5071 info sse4_crc32@4.1.1 Failed to exec install script
5072 verbose stack Error: sse4_crc32@4.1.1 install: `node-gyp rebuild`
5072 verbose stack Exit status 1
5072 verbose stack     at EventEmitter.<anonymous> (/opt/elasticbeanstalk/node-install/node-v4.2.1-linux-x64/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
5072 verbose stack     at emitTwo (events.js:87:13)
5072 verbose stack     at EventEmitter.emit (events.js:172:7)
5072 verbose stack     at ChildProcess.<anonymous> (/opt/elasticbeanstalk/node-install/node-v4.2.1-linux-x64/lib/node_modules/npm/lib/utils/spawn.js:24:14)
5072 verbose stack     at emitTwo (events.js:87:13)
5072 verbose stack     at ChildProcess.emit (events.js:172:7)
5072 verbose stack     at maybeClose (internal/child_process.js:818:16)
5072 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
5073 verbose pkgid sse4_crc32@4.1.1
5074 verbose cwd /tmp/deployment/application
5075 error Linux 4.1.10-17.31.amzn1.x86_64
5076 error argv "/opt/elasticbeanstalk/node-install/node-v4.2.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.2.1-linux-x64/bin/npm" "--production" "rebuild"
5077 error node v4.2.1
5078 error npm  v2.14.7
5079 error code ELIFECYCLE
5080 error sse4_crc32@4.1.1 install: `node-gyp rebuild`
5080 error Exit status 1
5081 error Failed at the sse4_crc32@4.1.1 install script 'node-gyp rebuild'.
5081 error This is most likely a problem with the sse4_crc32 package,
5081 error not with npm itself.
5081 error Tell the author that this fails on your system:
5081 error     node-gyp rebuild
5081 error You can get their info via:
5081 error     npm owner ls sse4_crc32
5081 error There is likely additional logging output above.
5082 verbose exit [ 1, true ]

package.json


  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": 
    "test": "mocha"
  ,
  "dependencies": 
    "async": "^0.8.0",
    "aws-sdk": "^2.2.21",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.0.2",
    "config": "^1.16.0",
    "cors": "^2.7.1",
    "crypto": "0.0.3",
    "crypto-js": "^3.1.5",
    "debug": "^0.7.4",
    "express": "^4.0.0",
    "express-jwt": "^0.4.0",
    "express-validator": "^2.3.0",
    "fs": "0.0.2",
    "jade": "^1.3.1",
    "jsonwebtoken": "^5.0.0",
    "mongoose": "^4.0.0",
    "morgan": "^1.0.1",
    "multer": "^1.1.0",
    "nodemailer": "^1.8.0",
    "os-shim": "^0.1.3",
    "prompt": "^0.2.14",
    "request": "^2.67.0",
    "validator": "^3.22.1"
  ,
  "devDependencies": 
    "chai": "^1.9.1",
    "chance": "^0.5.9",
    "mocha": "^1.18.2",
    "node-inspector": "^0.12.3",
    "supertest": "^0.13.0"
  

EB 控制台中抛出的错误:

2015-12-05 08:44:49 UTC+0700    ERROR   During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
2015-12-05 08:44:49 UTC+0700    ERROR   Failed to deploy application.
2015-12-05 08:44:49 UTC+0700    ERROR   Unsuccessful command execution on instance id(s) 'i-65c4d5dc'. Aborting the operation.
2015-12-05 08:44:49 UTC+0700    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2015-12-05 08:44:49 UTC+0700    ERROR   [Instance: i-65c4d5dc] Command failed on instance. Return code: 1 Output: (TRUNCATED)..."/opt/elasticbeanstalk/containerfiles/ebnode.py", line 166, in npm_install raise e subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v4.2.1-linux-x64/bin/npm', '--production', 'rebuild']' returned non-zero exit status 1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

这是我正在尝试的 .ebextensions/config.config:

packages:
  yum:
    gcc: []
    make: []
    openssl-devel: []
    libxml2: []
    libxml2-devel: []
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: root
    content: |
      #!/bin/bash
      function error_exit
      
      eventHelper.py --msg "$1" --severity ERROR
      exit $2
      

      export HOME=/home/ec2-user # ADDED EXPORT COMMAND
      echo "export home" # JUST FOR REMARK

      OUT=$(/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm- install 2>&1) || error_exit "Failed to run npm install. $OUT" $?
      echo $OUT

看起来错误来自 node-gyp 或 sse4_crc32。

我应该在 .ebextensions 文件中使用一些配置来解决这个问题吗?

谢谢

【问题讨论】:

【参考方案1】:

解决了。

EB 配置文件修复了它。我的路径是 .ebextensions/config.config

packages:
  yum:
    gcc: []
    make: []
    openssl-devel: []
    libxml2: []
    libxml2-devel: []
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: root
    content: |
      #!/bin/bash
      function error_exit
      
      eventHelper.py --msg "$1" --severity ERROR
      exit $2
      

      export HOME=/home/ec2-user # ADDED EXPORT COMMAND
      echo "export home" # JUST FOR REMARK

      OUT=$(/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm- install 2>&1) || error_exit "Failed to run npm install. $OUT" $?
      echo $OUT

NPM 任务中的主目录似乎可以完成这项工作。

还有一些让我望而却步的关键——在 Mac GUI 中压缩项目不会压缩隐藏文件。这可以通过在命令行中使用来克服:

zip -r archive_name.zip * .*

【讨论】:

抱歉,我看不出导出 HOME 代码有什么不同。和之前一样。我错过了什么吗?我有同样的问题,想知道这个解决方案是否可以节省我的时间。 问题出在我相信的文件的路径上......不是export home的东西 @PhilHudson 文件的路径应该是什么?我遇到了同样的问题,不知道我做错了什么。 你的意思是:.ebextensions/config.config 吗?

以上是关于将 NodeJS 部署到 Elastic Beanstalk 时出现 NPM 错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 ZIP 将 nodejs 应用程序部署到 Elastic BeanStalk => 找不到本地包

Bcrypt Elastic beanstalk nodejs 部署

我应该将使用 Elastic Beanstalk 部署的 NodeJS 应用程序的 API 密钥存储在哪里?

如何将 node.js 应用程序部署到 AWS Elastic Beanstalk

将 MongoDB 与 AWS Elastic Bean 应用程序一起使用

将 MongoDB 与部署在 Elastic Beanstalk 上的 NodeJS 应用程序一起使用的推荐方法是啥?