首页 > 解决方案 > AWS ElasticBeanstalk 节点部署无法运行 npm 安装。快照日志以获取更多详细信息

问题描述

我正在尝试在 aws 的 ElasticBeanstalk 上部署一个 node express,react 应用程序。但是在实例上 npm 安装期间应用程序部署失败。

上传完成。2018-12-22 20:12:20 INFO 环境更新开始。2018-12-22 20:12:23 INFO 将新版本部署到实例。2018-12-22 20:12:48 错误无法运行 npm install。快照日志以获取更多详细信息。2018-12-22 20:12:50 错误 [实例:i-0a7458ff1bef89f9a] 命令在实例上失败。返回代码:1 输出:(TRUNCATED)...opt/elasticbeanstalk/containerfiles/ebnode.py",第 180 行,在 npm_install raise e subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v10 .14.1-linux-x64/bin/npm', '--production', 'install']' 返回非零退出状态 1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh 失败。更多详细信息,请使用控制台或 EB CLI 检查 /var/log/eb-activity.log。2018-12-22 20:12:50 INFO 命令执行已在所有实例上完成。摘要:[成功:0,失败:1]。2018-12-22 20:12:50
错误在实例 ID“i-0a7458ff1bef89f9a”上执行命令不成功。中止操作。2018-12-22 20:12:50
错误无法部署应用程序。
错误:ServiceError - 无法部署应用程序。

package.json
{
  "name": "express-react-boilerplate",
  "version": "1.0.0",
  "description": "boiler plate node + react app",
  "main": "index.js",
  "scripts": {
    "start:dev": "NODE_ENV=dev nodemon node server/app.js",
    "start:test": "NODE_ENV=test node server/app.js",
    "start:prod": "NODE_ENV=prod node server/app.js",
    "format": "prettier es5 --single-quote --write '**/*.js'",
    "format-check": "prettier-check es5 --single-quote --write '**/*.js'",
    "react:watch": "webpack --mode development --watch",
    "react:build": "webpack --mode development",
    "dev-env": "npm-run-all --parallel start:dev react:watch",
    "test:server": "npm run format-check && ava server/tests/* --verbose",
    "test:client": "npm run format-check && ava client/tests/**/*.test.js --verbose",
    "test:client:watch": "npm run format-check && ava client/tests/**/*.test.js --verbose --watch --coverage",
    "test": "npm run format-check && ava */tests/**/*.test.js --verbose",
    "coverage": "nyc npm run test"
  },
  "dependencies": {
    "@babel/cli": "^7.1.5",
    "@babel/core": "^7.1.6",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    "@callstack/react-theme-provider": "^1.0.7",
    "axios": "^0.18.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-loader": "^8.0.4",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "browser-env": "^3.2.5",
    "chai": "^4.2.0",
    "css-loader": "^1.0.1",
    "dotenv": "^6.1.0",
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.7.0",
    "express": "^4.16.4",
    "express-status-monitor": "^1.2.3",
    "node-sass": "^4.10.0",
    "pino": "^5.8.1",
    "pino-pretty": "^2.2.4",
    "prettier": "^1.15.2",
    "prettier-check": "^2.0.0",
    "react": "^16.6.3",
    "react-addons-test-utils": "^15.6.2",
    "react-dom": "^16.6.3",
    "react-intl": "^2.7.2",
    "react-redux": "^5.1.1",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.1",
    "redux-mock-store": "^1.5.3",
    "request": "^2.88.0",
    "sass-loader": "^7.1.0",
    "sinon": "^7.1.1",
    "style-loader": "^0.23.1",
    "supertest": "^3.3.0",
    "webpack": "^4.26.0",
    "webpack-cli": "^3.1.2",
    "whatwg-fetch": "^3.0.0"
  },
  "devDependencies": {
    "ava": "1.0.0-rc.2",
    "create-ava": "^2.0.1",
    "istanbul": "^0.4.5",
    "nodemon": "^1.18.6",
    "npm-run-all": "^4.1.3",
    "nyc": "^13.1.0"
  },
  "ava": {
    "babel": {
      "testOptions": {
        "presets": [
          "@babel/preset-env",
          "@babel/preset-react"
        ]
      }
    },
    "require": [
      "@babel/register",
      "@babel/polyfill",
      "./client/tests/config.js",
      "./client/tests/helpers/browserEnvironment.js"
    ]
  }
}

我无法弄清楚部署出了什么问题。

日志说有关 python 2 not found 但我不确定这是否是问题所在。以下是日志供参考

------------------------------------- /var/log/eb-activity.log --- ---------------------------------- gyp动词cli ['/opt/elasticbeanstalk/node-install/node- v10.14.1-linux-x64/bin/node',gyp动词cli
'/tmp/deployment/application/node_modules/node-gyp/bin/node-gyp.js',gyp动词cli'rebuild',gyp
动词cli' --verbose',gyp动词cli'--libsass_ext=',gyp动词cli'--libsass_cflags=',gyp动词cli'--libsass_ldflags=',gyp动词cli'--libsass_library='] gyp信息使用节点- gyp@3.8.0 使用 node@10.14.1 的 gyp 信息 | linux | x64 gyp 动词命令重建 [] gyp 动词命令清理 [] gyp 动词清理删除“构建”which失败错误:未找到:python2 gyp 动词which 在 getNotFoundError 失败(/tmp/deployment/application/node_modules/which/which.js:13:12)gyp 动词which在 F 失败(/tmp/deployment/application/node_modules/which/which .js:68:19) gyp 动词which在 E (/tmp/deployment/application/node_modules/which/which.js:80:29) gyp 动词which在 /tmp/deployment/application/node_modules/which/which.js 失败:89:16 whichgyp 动词在 /tmp/deployment/application/node_modules/isexe/index.js:42:5 gyp 动词which在 /tmp/deployment/application/node_modules/isexe/mode.js 失败:8:5 gyp 动词 whichFSReqWrap.oncomplete (fs.js:154:21) gyp 动词 which失败 python2 { 错误:未找到:python2 gyp 动词whichwhichgetNotFoundError 失败 (/tmp/deployment/application/node_modules/which/which.js:13:12) gyp 动词在 F (/tmp/deployment/application/node_modules/which/which.js:68:19) gyp 动词失败which在 E (/tmp/deployment/application/node_modules/which/which.js:80:29)which失败,gyp 动词在 /tmp/deployment/application/node_modules/which/which.js:89:16 gyp 动词which失败 / tmp/deployment/application/node_modules/isexe/index.js:42:5 gyp 动词在 /tmp/deployment/application/node_modules/isexe/mode.js:8:5 whichgyp 动词 which在 FSReqWrap.oncomplete 失败(fs.js :154:21) gyp 动词 which失败堆栈:gyp 动词whichfailed '错误:未找到:python2\n at getNotFoundError (/tmp/deployment/application/node_modules/which/which.js:13:12)\n
at F (/tmp/deployment/application/node_modules/which/which. js:68:19)\n 在 E (/tmp/deployment/application/node_modules/which/which.js:80:29)\n 在 /tmp/deployment/application/node_modules/which/which.js:89: 16\n
在 /tmp/deployment/application/node_modules/isexe/index.js:42:5\n
在 /tmp/deployment/application/node_modules/isexe/mode.js:8:5\n 在 FSReqWrap.oncomplete ( fs.js:154:21)', gyp verb whichfailed
code: 'ENOENT' } gyp verb check python 检查 PATH 中的 Python 可执行文件“python” gyp verbwhich成功 python /usr/bin/python gyp verb 检查 python 版本/usr/bin/python -c "import sys; print "2.7.15 gyp verb check python version .%s.%s" % sys.version_info[:3];"返回:%j gyp verb get node dir no --target version specified, fall back to host node version: 10.14.1 gyp verb command install [ '10.14.1' ] gyp verb install input version string "10.14.1" gyp verb install 安装版本: 10.14.1 gyp verb install --ensure 已通过,所以如果已经安装 gyp verb install version 已经安装,则不会重新安装,需要检查“installVersion” gyp verb得到“installVersion” 9 gyp verb需要“installVersion " 9 gyp verb install version is good gyp verb get node dir target node version installed: 10.14.1 gyp verb build dir trying to create "build" dir: /tmp/deployment/application/node_modules/node-sass/build gyp ERR!配置错误gyp ERR!堆栈错误:EACCES:权限被拒绝,mkdir '/tmp/deployment/application/node_modules/node-sass/build' gyp 错误!系统 Linux 4.14.77-70.82.amzn1.x86_64 gyp ERR!命令“/opt/elasticbeanstalk/node-install/node-v10.14.1-linux-x64/bin/node”“/tmp/deployment/application/node_modules/node-gyp/bin/node-gyp.js”“重建” "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp 错误!cwd /tmp/deployment/application/node_modules/node-sass gyp ERR!节点 -v v10.14.1 gyp 错误!节点-gyp -v v3.8.0 gyp 错误!不正常构建失败,错误代码:1 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: Want {"node scripts/build.js npm 错误!退出状态 1 npm ERR!npm 错误!在 node-sass@4.10.0 安装后脚本失败。npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!/tmp/.npm/_logs/2018-12-22T20_12_48_626Z-debug.log 运行 npm 安装:/opt/elasticbeanstalk/node-install/node-v10.14.1-linux-x64/bin/npm
将 npm config 作业设置为 1 npm config 作业设置为 1 运行带有 --production 标志的 npm 无法运行 npm install。快照日志以获取更多详细信息。UTC 2018/12/22 20:12:48 在 /tmp/deployment/application/npm-debug.log 中找不到应用程序 npm 调试日志 Traceback(最近一次调用最后一次):文件“/opt/elasticbeanstalk/containerfiles/ebnode.py ”,第 695 行,在 main() 文件中“/opt/elasticbeanstalk/containerfiles/ebnode.py”,第 677 行,在主 node_version_manager.run_npm_install(options.app_path) 文件中“/opt/elasticbeanstalk/containerfiles/ebnode.py”,第 136 行,在 run_npm_install self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir')) 文件“/opt/elasticbeanstalk/containerfiles/ebnode.py”中,第 180 行,

[2018-12-22T20:12:48.669Z] 信息 [4110] - [应用程序更新 app-6694-181222_201205@3/AppDeployStage0/AppDeployPreHook/50npm.sh]:活动失败。[2018-12-22T20:12:48.669Z] 信息 [4110] - [应用程序更新 app-6694-181222_201205@3/AppDeployStage0/AppDeployPreHook]:活动失败。[2018-12-22T20:12:48.669Z] 信息 [4110] - [应用程序更新 app-6694-181222_201205@3/AppDeployStage0]:活动失败。[2018-12-22T20:12:48.670Z] 信息 [4110] - [应用程序更新 app-6694-181222_201205@3]:已完成活动。结果:应用程序更新 - 命令 CMD-AppDeploy 失败 [2018-12-22T20:17:12.316Z] 信息 [4490] - [CMD-TailLogs] :开始活动... [2018-12-22T20:17:12.316Z]信息 [4490] - [CMD-TailLogs/AddonsBefore]:开始活动... [2018-12-22T20:17:12.316Z] 信息 [4490] - [CMD-TailLogs/AddonsBefore]:完成的活动。[2018-12-22T20:17:12.316Z] 信息 [4490] - [CMD-TailLogs/TailLogs]:开始活动... [2018-12-22T20:17:12.316Z] 信息 [4490] - [CMD- TailLogs/TailLogs/TailLogs] : 开始活动...

标签: node.jsamazon-web-servicesexpressdevopsamazon-elastic-beanstalk

解决方案


看起来您有权限问题:

gyp verb build dir attempting to create "build" dir: /tmp/deployment/application/node_modules/node-sass/build gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/node-sass/build' gyp ERR! System Linux 4.14.77-70.82.amzn1.x86_64 gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v10.14.1-linux-x64/bin/node" 我不确定为什么会这样 - 你需要 sudo 访问权限吗?


推荐阅读