为什么我的ES6节点应用程序不会在弹性beanstalk中运行?

时间:2017-02-21 15:59:54

标签: node.js ecmascript-6 elastic-beanstalk babel

我的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)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

好像你正在使用eb CLI工具!

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

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