【问题标题】:Why won't my ES6 node app run in elastic beanstalk?为什么我的 ES6 节点应用程序不能在弹性 beantalk 中运行?
【发布时间】:2017-07-11 08:39:53
【问题描述】:

我的package.json 是:

{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "babel-node --presets es2015 server.js"
  },
  "engines": {
    "node": "~6.2.2"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.23.0",
    "babel-preset-es2015": "^6.22.0",
    "body-parser": "^1.16.1",
    "express": "^4.14.1",
    "faker": "^3.1.0",
    "lodash": "^4.17.4"
  }
}

我的.elasticbeantalk/config.yml

branch-defaults:
  master:
    environment: mysite-api-dev
    group_suffix: null
global:
  application_name: mysite-api
  branch: null
  default_ec2_keyname: mysite-aws
  default_platform: Node.js
  default_region: us-east-1
  profile: eb-cli-mysite
  repository: null
  sc: git

但是当我部署和执行时,我得到一个502 错误。于是我查了一些日志,似乎不支持 ES6:

============= i-0c6e00622a7b74a8f ==============
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
/var/app/current/server.js:1
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash'
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

我做错了什么?

【问题讨论】:

  • 您的 EBS 实例上运行的 Node 版本是什么?
  • 我怎样才能知道?难道不应该尊重我在package.json中的engines吗?

标签: node.js ecmascript-6 amazon-elastic-beanstalk babeljs


【解决方案1】:

看来您正在使用 eb CLI 工具!

只需在你的工作空间中使用eb status,并查看平台字段以检查当前运行的 Node 版本。

eb CLI 的文档:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-status.html

【讨论】:

猜你喜欢
  • 2017-03-12
  • 2019-05-26
  • 2014-05-24
  • 1970-01-01
  • 2017-04-12
  • 2015-05-28
  • 2018-03-26
  • 2018-02-12
  • 2013-07-09
相关资源
最近更新 更多