3

I was settings up a new system to use CodeceptJS and have hit an issue. I followed these notes, but just get an error when trying to run codeceptjs. The error is...

codeceptjs
/usr/local/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/mocha_factory.js:6
let mocha;
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/container.js:5:20)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

My node.js and npm is installed globally via normal apt-get and npm -g

System info...

  • Ubuntu 17.04 x86_64
  • nodejs: 4.7.2
  • npm: 4.5.0
  • bash 4.4.5

Does anyone know the cause of this issue or how to get around it?


Just as an update, thanks to artem for the note on 'use strict'; I added that to the top of node_modules/codeceptjs/lib/mocha_factory.js and that, I think, got me past the initial problem. However I now seem to be hitting an issue in node_modules/codeceptjs/lib/output.js. The error is...

codeceptjs
/usr/local/lib/node_modules/codeceptjs-nightmare/node_modules/codeceptjs/lib/output.js:139
function print(...msg) {
               ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/codeceptjs-nightmare/node_modules/codeceptjs/lib/event.js:3:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

...I've tried a few things to resolve this, adjusting the print function there, but with no luck yet.

This seems to be the same with the codeceptjs-nightmare and codeceptjs-webdriverio meta-packages.

I'd be grateful of any ideas, suggestions or alternatives anyone has.

iehrlich
  • 3,524
  • 4
  • 30
  • 42
AndyGaskell
  • 522
  • 6
  • 19
  • I get the same error with a global or local install – AndyGaskell Apr 28 '17 at 11:29
  • may be you are not install web drive packages properly – Kasiriveni Apr 28 '17 at 11:39
  • @Kasiriveni thanks for your comment, I tried 'sudo npm install -g codeceptjs-webdriverio' and 'sudo npm install -g codeceptjs' and got the same error. Did I miss something? – AndyGaskell Apr 28 '17 at 11:54
  • 1
    looks like a bug introduced in [0.6.1](https://github.com/Codeception/CodeceptJS/pull/479/commits/657c5a65f6f6c590b4f95f575ea808aa7e9936b8#diff-767dba500363101a476f0b1732f755ad) : [this file](https://github.com/Codeception/CodeceptJS/blob/master/lib/mocha_factory.js) in missing `'use strict';` at the top – artem May 03 '17 at 21:32
  • I also tried this on a different Ubuntu 16.04.1 LTS and saw exactly the same. – AndyGaskell May 05 '17 at 20:00

1 Answers1

2

Your second issue is because of an outdated Node version. The spread operator (the ... error that you're seeing) is supported in Node 5.12.0 and later: http://node.green/#ES2015-syntax-spread-------operator

I'm not sure what the best way for you to upgrade is with Ubuntu, but that should solve your issue.

Chris White
  • 731
  • 6
  • 17
  • Thanks Chris, that's great. I updated to Node.js 7 and it's all working lovely now. I updated by following notes on https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions and I also jotted an issue on https://github.com/Codeception/CodeceptJS/issues/505 though it's more about documentation really. – AndyGaskell May 05 '17 at 23:26