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)
I'm using cucumberjs to do some BDD. I have a feature with two screnarios. They work when run in the terminal, when all of the js is in one file. I want to have the GroceryList class in a seperate file to make it cleaner.
I do the import like this:
'use strict';
import * as a from "grocery-list";
I do the export like this:
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;
}
}
}
What am I doing wrong to get this error? Google searches of the issue say things like:
It looks like it can't find babel and babel-core. Do you have those on your node_modules directory?
I have a lot of node_modules directories so not quite sure what to do. But I believe cucumberjs uses node.js. I just can't see where in the code it references node.js.
I updated to the latest version of node.js. Here is my terminal running my cucumber.js feature and the new error I am getting:
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$
Here are my node --v8-options
options for --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