Node.JS不间断语法错误

时间:2016-10-08 05:49:21

标签: javascript node.js

当我尝试在我的VPS上运行discord bot时,我一直遇到语法错误。我在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);

我使用的是Node版本v0.10.46。

1 个答案:

答案 0 :(得分:1)

您正在使用Node的旧版分支,它使用较旧版本的V8,因此对新ES6语法的支持有限。

来自release versions页面:

  
      
  • 版本:Node.js v0.10.46
  •   
  • 日期:2016-06-23
  •   
  • V8:3.14.5.9
  •   
  • npm:2.15.1
  •   
  • NODE_MODULE_VERSION:11
  •   

我们可以看到此版本的Node使用V8版本3.14.5.9。与使用V8 5.1.281.83

的v6.7.0相比
  
      
  • 版本:Node.js v6.7.0
  •   
  • 日期:2016-09-27
  •   
  • V8:5.1.281.83
  •   
  • npm:3.10.3
  •   
  • NODE_MODULE_VERSION:48
  •   

可能的解决方案包括使用Node的新分支,或者首先通过转换器运行代码。