2015-12-28 54 views
3
Benjamins-MacBook-Pro:Features Ben$ cucumber.js addItem.feature 
/Users/Ben/WhatWeGrow.Web/public/Features/addItem.step.js:4 
import * as a from "grocery-list"; 
^^^^^^ 

SyntaxError: Unexpected reserved word 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:414:25) 
    at Object.Module._extensions..js (module.js:442:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:311:12) 
    at Module.require (module.js:366:17) 
    at require (module.js:385:17) 
    at /usr/local/lib/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:63:29 
    at Array.forEach (native) 
    at Object.wrapper (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:62:15) 

我使用cucumberjs做一些BDD。我有兩個screnarios的功能。他們在終端運行時工作,當所有的js都在一個文件中。我想在一個單獨的文件中使GroceryList類更清潔。的JavaScript模塊 - 語法錯誤:意外的保留字在exports.runInThisContext

我做這樣的進口:

'use strict'; 

import * as a from "grocery-list"; 

我不喜歡這個出口:

module.exports = function() { 

    class GroceryList { 

    constructor() { 
     this.list = { 
     value: [], 
     writable: false, 
     enumerable: true 
     }; 
    } 

    add(item) { 
     this.list.value.push(item); 
    } 

    getAll() { 
     return this.list.value; 
    } 

    getItemIndex(value) { 
     var index = this.list.value.length; 
     while (--index > -1) { 
     if (this.list.value[index] === value) { 
      return index; 
     } 
     } 
     return -1; 
    } 
    } 
    } 

我在做什麼錯得到這個錯誤?問題的谷歌搜索說這樣的話:

It looks like it can't find babel and babel-core. Do you have those on your node_modules directory?

我有很多node_modules目錄所以不太知道該怎麼做。但我相信cucumberjs使用node.js。我只是看不到它引用node.js的代碼。

我更新到最新版本的node.js.這裏是我的終端運行我cucumber.js功能和新的錯誤我得到:

Benjamins-MacBook-Pro:Features Ben$ node -v 
v4.2.3 
Benjamins-MacBook-Pro:Features Ben$ node -v 
v5.3.0 
Benjamins-MacBook-Pro:Features Ben$ cucumber.js addItem.feature 
/Users/Ben/WhatWeGrow.Web/public/Features/addItem.step.js:4 
import * as a from "grocery-list"; 
^^^^^^ 

SyntaxError: Unexpected token import 
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:374:25) 
    at Object.Module._extensions..js (module.js:405:10) 
    at Module.load (module.js:344:32) 
    at Function.Module._load (module.js:301:12) 
    at Module.require (module.js:354:17) 
    at require (internal/module.js:12:17) 
    at /usr/local/lib/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:63:29 
    at Array.forEach (native) 
    at Object.wrapper (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:62:15) 
Benjamins-MacBook-Pro:Features Ben$ 

這裏是我node --v8-options選項--harmony

es_staging (enable all completed harmony features) 
     type: bool default: false 
    --harmony (enable all completed harmony features) 
     type: bool default: false 
    --harmony_shipping (enable all shipped harmony fetaures) 
     type: bool default: true 
    --legacy_const (legacy semantics for const in sloppy mode) 
     type: bool default: true 
    --harmony_modules (enable "harmony modules" (in progress)) 
     type: bool default: false 
    --harmony_regexps (enable "harmony regular expression extensions" (in progress)) 
     type: bool default: false 
    --harmony_proxies (enable "harmony proxies" (in progress)) 
     type: bool default: false 
    --harmony_sloppy_function (enable "harmony sloppy function block scoping" (in progress)) 
     type: bool default: false 
    --harmony_sloppy_let (enable "harmony let in sloppy mode" (in progress)) 
     type: bool default: false 
    --harmony_unicode_regexps (enable "harmony unicode regexps" (in progress)) 
     type: bool default: false 
    --harmony_reflect (enable "harmony Reflect API" (in progress)) 
     type: bool default: false 
    --harmony_destructuring (enable "harmony destructuring" (in progress)) 
     type: bool default: false 
    --harmony_default_parameters (enable "harmony default parameters" (in progress)) 
     type: bool default: false 
    --harmony_sharedarraybuffer (enable "harmony sharedarraybuffer" (in progress)) 
     type: bool default: false 
    --harmony_atomics (enable "harmony atomics" (in progress)) 
     type: bool default: false 
    --harmony_simd (enable "harmony simd" (in progress)) 
     type: bool default: false 
    --harmony_array_includes (enable "harmony Array.prototype.includes") 
     type: bool default: false 
    --harmony_tostring (enable "harmony toString") 
     type: bool default: false 
    --harmony_concat_spreadable (enable "harmony isConcatSpreadable") 
     type: bool default: false 
    --harmony_rest_parameters (enable "harmony rest parameters") 
     type: bool default: false 
    --harmony_sloppy (enable "harmony features in sloppy mode") 
     type: bool default: false 
    --harmony_arrow_functions (enable "harmony arrow functions") 
     type: bool default: true 
    --harmony_new_target (enable "harmony new.target") 
     type: bool default: true 
    --harmony_object_observe (enable "harmony Object.observe") 
     type: bool default: true 
    --harmony_spreadcalls (enable "harmony spread-calls") 
     type: bool default: true 
    --harmony_spread_arrays (enable "harmony spread in array literals") 
     type: bool default: true 
    --harmony_object (enable "harmony Object methods") 
     type: bool default: true 
+2

確保您獲得的Node版本支持ES2015。 – Pointy

+0

@Pointy我剛剛升級了我的node.js並用新的錯誤更新了我的問題。 – Ben

+0

您可能必須明確要求ES2015(「和聲」)功能。執行'node --v8-options'並查看'--harmony'選項的默認值。 – Pointy

回答

0

節點不具備的EcmaScript模塊的支持,然而。