IBM bluemix 上的 ES6 模块语法支持

ES6 modules syntax support on IBM bluemix

我有一个使用 ES6 导入语句的应用程序。我尝试将它部署在 ibm cloudfoundry 上。日志显示它从节点 6.8.0 开始。该应用程序抱怨:

 Unexpected token import

我在我的 windows 10 桌面上启动了应用程序,节点为 6.8.0,它运行完美。我 运行 :

console.log(process.versions);

这是输出:

{ http_parser: '2.7.0',
  node: '6.8.0',
  v8: '5.1.281.84',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '57.1',
  modules: '48',
  openssl: '1.0.2j' }

输出在我的机器上是相同的,在我的机器上应用程序工作,而在 bluemix 服务器上它不工作。这是我的 Package.json:

    {
  "name": "bluemixtest",
  "version": "0.0.0",
  "main": "server/app.js",
  "dependencies": {
  },
  "devDependencies": {
  },
  "engines": {
    "node": "6.8.0"
  },
  "scripts": {
    "start": "node --harmony_modules server/app.js"
  },
  "private": true
}

server/app.js:

'use strict';
import express from 'express';
import mongoose from 'mongoose';

日志中的启动错误:

/home/vcap/app/server/app.js:7
import express from 'express';
^^^^^^
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)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
npm ERR! Linux 3.19.0-33-generic
npm ERR! argv "/home/vcap/app/vendor/node/bin/node" "/home/vcap/app/vendor/node/bin/npm" "start"
npm ERR! node v6.8.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! bluemixtest@0.0.0 start: `node --harmony server/app.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bluemixtest@0.0.0 start script 'node --harmony server/app.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bluemixtest package,
npm ERR! not with npm itself.

尽管 es6 标准定义了 import 语句,但节点本身不支持它(目前)。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import