“npm install”在弹性 beantalk 上失败,但是手动执行有效
Posted
技术标签:
【中文标题】“npm install”在弹性 beantalk 上失败,但是手动执行有效【英文标题】:"npm install" failing on elastic beanstalk, however manual execution works 【发布时间】:2018-02-17 00:19:40 【问题描述】:我已经检查了这个answer,这似乎不是我的问题。 我正在使用 react 的弹性 beantalk 上部署 django 代码。为了编译反应文件,我运行 npm install 和 npm run build 似乎失败了。这些在 .ebextensions 配置文件中指定。
但是,如果我 ssh 进入实例并设置环境并手动运行 npm install ,那么它可以正常工作而不会失败。
我对发生了什么感到困惑?
这是 npm-debug.log
的尾部70623 silly install node-sass@4.5.3 /opt/python/bundle/3/app/eb_miral/node_modules/.staging/node-sass-db50db14
70624 info lifecycle node-sass@4.5.3~install: node-sass@4.5.3
70625 verbose lifecycle node-sass@4.5.3~install: unsafe-perm in lifecycle true
70626 verbose lifecycle node-sass@4.5.3~install: PATH: /usr/lib/node_modules/npm/bin/node-gyp- bin:/opt/python/bundle/3/app/eb_miral/node_modules/node-sass/node_modules/.bin:/opt/pyth$
70627 verbose lifecycle node-sass@4.5.3~install: CWD: /opt/python/bundle/3/app/eb_miral/node_modules/node-sass
70628 silly lifecycle node-sass@4.5.3~install: Args: [ '-c', 'node scripts/install.js' ]
70629 verbose stack Error: spawn ENOMEM
70629 verbose stack at exports._errnoException (util.js:1020:11)
70629 verbose stack at ChildProcess.spawn (internal/child_process.js:328:11)
70629 verbose stack at exports.spawn (child_process.js:369:9)
70629 verbose stack at spawn (/usr/lib/node_modules/npm/lib/utils/spawn.js:21:13)
70629 verbose stack at runCmd_ (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:247:14)
70629 verbose stack at runCmd (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:208:5)
70629 verbose stack at runPackageLifecycle (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:174:3)
70629 verbose stack at Array.<anonymous> (/usr/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
70629 verbose stack at LOOP (/usr/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:14)
70629 verbose stack at chain (/usr/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:5)
70630 verbose cwd /opt/python/bundle/3/app
70631 error Linux 4.9.43-17.38.amzn1.x86_64
70632 error argv "/usr/bin/node" "/usr/bin/npm" "install" "--prefix" "./eb_miral/"
70633 error node v6.11.3
70634 error npm v3.10.10
70635 error code ENOMEM
70636 error errno ENOMEM
70637 error syscall spawn
70638 error spawn ENOMEM
70639 error If you need help, you may report this error at:
70639 error <https://github.com/npm/npm/issues>
70640 verbose exit [ 1, true ]
eb-commandprocessor.log
[2017-09-08T06:18:43.012Z] ERROR [7803] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: npm WARN prefer global node-gyp@3.6.2 should be installed with -g
> node-sass@4.5.3 install /opt/python/bundle/3/app/eb_miral/node_modules/node-sass
> node scripts/install.js
(ElasticBeanstalk::ExternalInvocationError)
[2017-09-08T06:18:43.012Z] ERROR [7803] : Command CMD-AppDeploy failed!
[2017-09-08T06:18:43.029Z] INFO [7803] : Command processor returning results:
"status":"FAILURE","api_version":"1.0","results":["status":"FAILURE","msg":"npm WARN prefer global node-gyp@3.6.2 should be installed with -g\n\n> node-sass@4.5.3 install /opt/python/bundle/3/app/eb_miral/node_modules/node-sass\n> node scripts/install.js. \ncontainer_command 03_npm_build in .ebextensions/02_python.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]]
.ebextension/01_packages.config 安装节点
packages:
yum:
git: []
postgresql93-devel: []
libjpeg-turbo-devel: []
commands:
01_node_install:
cwd: /tmp
test: '[ ! -f /usr/bin/npm ] && echo "npm not installed"'
command: 'curl --silent --location https://rpm.nodesource.com/setup_6.x | bash - && yum -y install nodejs'
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
.ebextensions/02_python.config 用于运行npm install
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python eb_miral/manage.py migrate --settings=miral.settings.production --noinput"
leader_only: true
02_createsu:
command: "source /opt/python/run/venv/bin/activate && python eb_miral/manage.py createsu --settings=miral.settings.production"
leader_only: true
# You can define a build script in packages.json (using gulp, grunt...) to build your client side files
03_npm_build:
command: 'npm install --prefix ./eb_miral/ && npm --prefix ./eb_miral/ run build'
04_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python eb_miral/manage.py collectstatic --noinput --settings=miral.settings.production"
leader_only: true # Because it should push everything to cloud only once
添加更多细节: npm版本为3.10.10,node版本为6.11.3,npm registry为https://registry.npmjs.org/,架构为Linux。
【问题讨论】:
【参考方案1】:解决了。似乎 ENOMEM 错误在部署到 t2.micro 实例时经常发生。当部署在 ec2 实例上耗尽内存时会发生这种情况。 通过添加交换空间来修复它。查看此answer 了解更多详情。
【讨论】:
以上是关于“npm install”在弹性 beantalk 上失败,但是手动执行有效的主要内容,如果未能解决你的问题,请参考以下文章
如何使用弹性 beantalk 中的 express.js 进行反应构建?