【问题标题】:Elastic Beanstalk to run 'concurrently' command via npm scriptElastic Beanstalk 通过 npm 脚本运行“并发”命令
【发布时间】:2018-07-19 09:01:30
【问题描述】:

我正在尝试将我的 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 安装为开发依赖项,但我知道 Elastic Beanstalk 也会安装开发依赖项,除非另有要求。

通过谷歌搜索,我怀疑 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

【问题讨论】:

  • 您可以添加描述您的错误的日志吗?
  • @toddg 我编辑了我的帖子并添加了您要求的错误日志。

标签: node.js amazon-ec2 amazon-elastic-beanstalk


【解决方案1】:

根据 SO 上发布的 this answer,Elastic Beanstalk 现在默认运行 npm install --production。因此,您有两个选项可以同时安装 npm 包。

  1. 将其添加到您的生产依赖项中。
  2. 指示 Elastic Beanstalk 不要添加 --production 标志。

选项 1 更易于实施(尽管可能无法满足您的要求)。选项 2 将涉及将 any.config(名称无关紧要)文件添加到项目根目录中的 .ebextensions 目录,其中包含以下 yaml:

option_settings:
- namespace: aws:elasticbeanstalk:application:environment
  option_name: NPM_USE_PRODUCTION
  value: false

如果您已为您的 EB 实例设置了 ssh,请通过 ssh 进入该实例并导航至 /var/app/current/node_modules。您可能会看到concurrently 不存在。

【讨论】:

  • 很好的答案。我能够使用您建议的选项安装并发包。
猜你喜欢
  • 2015-06-30
  • 2018-04-16
  • 2017-03-11
  • 2017-04-07
  • 2018-04-12
  • 2018-05-23
  • 2016-07-06
  • 2014-03-07
  • 2014-05-11
相关资源
最近更新 更多