我正在尝试将我的React + API服务器应用程序部署到AWS Elastic Beanstalk,并且现在遇到一些麻烦。
我正在关注此tutorial,我按照这样配置了我的npm脚本:
"scripts": {
"start": "concurrently \"npm run server\" \"npm run client\" ",
"server": "node server.js",
"client": "node start-client.js"
},
但是,当我读取失败的日志时,EC2似乎无法找到concurrently
命令。
Concurrently作为dev-dependencies安装,但我知道Elastic Beanstalk也会安装dev-dependencies,除非另有要求。
通过一些谷歌搜索,我怀疑EC2实例在其PATH中没有安装的节点包的位置,但我不太确定如何解决这个问题。
编辑:我从EBS日志控制台复制了错误日志。
\> kid-server@0.0.0 start /var/app/current
\> concurrently "npm run server" "npm run client"
sh: concurrently: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! kid-server@0.0.0 start: `concurrently "npm run server" "npm run client" `
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the kid-server@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm update check failed
Try running with sudo or get access
to the local update config store via
sudo chown -R $USER:$(id -gn $USER) /tmp/.config
答案 0 :(得分:1)
根据发布在SO上的this answer,Elastic Beanstalk现在默认运行npm install --production
。所以你有两个选择来同时安装npm包。
--production
标志。选项1更容易实现(尽管可能不符合您的要求)。选项2将涉及将any.config
(名称无关紧要)文件添加到项目根目录中包含以下yaml的.ebextensions
目录:
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: NPM_USE_PRODUCTION
value: false
如果你为你的EB实例设置了ssh,请ssh进入它并导航到/var/app/current/node_modules
。您可能会看到concurrently
不存在。