ICostaEx Designs
ICostaEx Designs

Reputation: 27

Node.JS nonstop syntax errors

I keep getting syntax errors when I attempt to run a discord bot on my VPS. I have all the required things installed on the VPS...

/root/node_modules/random.js:12 client.on('ready', () => {
                                                    ^ SyntaxError: Unexpected token )
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:945:3

const Discord = require('discord.js');
const request = require('superagent');
const fs = require('fs');

const client = new Discord.Client({ fetch_all_members: false,    
api_request_method: 'sequential' });


client.login(***);

client.on('ready', () => {
  console.log('ready!');
});

client.on('channelCreate', channel => {
console.log('made ${channel.name}');
});

client.on('guildMemberAdd', (g, m) => {
  console.log('${m.user.username} joined ${g.name}');
})

client.on('guildMemberUpdate', (g, o, n) => {
  console.log(o.nickname, n.nickname);
});

client.on('debug', console.log);

I'm using Node version v0.10.46.

Upvotes: 0

Views: 177

Answers (1)

Alexander O'Mara
Alexander O'Mara

Reputation: 60537

You are using a legacy branch of Node which uses a much older version of V8, so support for new ES6 syntax is limited.

From the release versions page:

  • Version: Node.js v0.10.46
  • Date: 2016-06-23
  • V8: 3.14.5.9
  • npm: 2.15.1
  • NODE_MODULE_VERSION: 11

We can see this version of Node uses V8 version 3.14.5.9. Contrast this with v6.7.0 which uses V8 5.1.281.83:

  • Version: Node.js v6.7.0
  • Date: 2016-09-27
  • V8: 5.1.281.83
  • npm: 3.10.3
  • NODE_MODULE_VERSION: 48

Possible solutions include using a newer branch of Node, or running you code through a transpiler first.

Upvotes: 1

Related Questions