Why is the Javascript not not starting?

July 23, 2018 170 views
Apache Ubuntu

I am running an UBUNTU 14 , trying to start a Javascript not for my game webapp but it returns This error:

:/var/www/html/bot# pm2 start site.js
.action(() => {
SyntaxError: Unexpected token )
at exports.runInThisContext (vm.js:73:16)
at Module.
compile (module.js:443:25)
at Object.Module.extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module.
load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

2 Answers
aha MOD July 24, 2018
Accepted Answer

That looks like the type of problem that comes up when your program is expecting a newer version of node or the javascript language than what your project is currently using.

The action(() => { syntax is an arrow function, a newer syntax to javascript introduced in ECMAScript 6/2015 spec. It has been supported in Node.js since version 6+

Potential Solution 1: See if you have an old version of node. Run node -v in the command line, confirm that you have a version greater than 6, if you have an old version follow these instructions to install nvm so you can just run a newer version of node for this bot project.

Potential Solution 2: Make sure there is a file here: /var/www/html/bot/.babelrc that contains:

"presets": [ "es2015" ]

You can check for the file by running ls -a and looking for it.

Thanks a lot.. worked now. used solution 1

Have another answer? Share your knowledge.