我已经检查了这个answer,这似乎不是我的问题。 我正在使用反应的弹性beanstalk上部署django代码。要编译react文件,我运行npm install和npm run build似乎失败了。这些在.ebextensions配置文件中指定。
但是,如果我进入实例并设置环境并手动运行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,节点版本是6.11.3,npm注册表是https://registry.npmjs.org/,架构是Linux。
答案 0 :(得分:1)
解决了它。似乎在部署到t2.micro实例时经常发生ENOMEM错误。当部署耗尽ec2实例上的内存时,会发生这种情况。 通过添加交换空间来修复它。有关详细信息,请查看此answer。