2

I get an error whilst running my node index.js here is my code

const botconfig = require("./botconfig.json");
const Discord = require("discord.js");

const bot = new Discord.Client({disableEveryone: true});


bot.on("ready", async () => {
console.log(`${bot.user.username} is online!`);
}};

bot.login(botconfig.token);

here is my error message

SyntaxError: missing ) after argument list
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:190:16)

hope you can help!

user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125
Ricky Dom
  • 21
  • 1
  • 2
  • 2
    you might wanna change `}};` to `});` – djnose Feb 19 '18 at 22:26
  • now I get this error Error: Cannot find module './botconfig/json' at Function.Module._resolveFilename (module.js:555:15) at Function.Module._load (module.js:482:25) at Module.require (module.js:604:17) at require (internal/module.js:11:18) at Object. (C:\Users\manni\Desktop\DiscordBot\index.js:1:81) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:573:32) at tryModuleLoad (module.js:513:12) at Function.Module._load (module.js:505:3) – Ricky Dom Feb 19 '18 at 23:07
  • @RickyDom - make sure your `botconfig.json` file is in the same directory as your `index.js` file – Blundering Philosopher Feb 20 '18 at 09:38

4 Answers4

1

If you see an error at new Script (vm.js:51:7), it means there's an error in a custom script that you passed to vm.js, the Node module that communicates with the V8 Virtual Machine.

new Script in vm.js is simply evaluating your code.

So you need to work out what the fault is in the code you passed to the V8 virtual machine. If you run the file directly (e.g. node some/path/some_file.js) you should get a pointer to the actual fault that looks like this:

YourPC:your-directory you$ node some/path/some_file.js
/some/system/path/your-directory./some/path/some_file.js:123
}};
 ^

SyntaxError: missing ) after argument list
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)

The part above the error message with the ^ caret shows you the faulty point in your own code.

In your case, it's pretty easy to spot: you have a }}; that should be a });.

If you have code that seems 100% fine but encounters this error, like @maevanapcontact's failing arrow functions, maybe you're using an old version of Node with an old version of V8 that didn't support that ECMAScript feature. Arrow functions didn't have complete support until Node version 6.

user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125
0

I had the same error as you and I have fixed it by using function(){}; instead of () =>. I don't really know why it doesn't work with arrow functions, but it did the job for me like that.

  • Are you using a version of Node from before Node 6? If so it's probably because [Node didn't have complete arrow function support back then](https://stackoverflow.com/questions/19644341/node-js-support-for-arrow-function). If not, there was probably a syntax error in the arrow function you didn't spot, which you fixed while changing the function type – user56reinstatemonica8 Mar 02 '18 at 11:58
  • I use the last version of Node (9.7.1) and I had copy/ paste the function from the documentation. I had made many checks but it is still not working with arrow functions – maevanapcontact Mar 03 '18 at 12:59
0

I found it helpful to add a break-point in vm.js where the error is thrown. (click on the filename link in the stack trace). Reload the page and then inspect the local variables. The filename variable will give the the full name of the js file that caused the error.

Unfortunately this isn't enough to narrow down the exact line, so I ended up deleting parts of the file until it would compile. From there I was able to narrow what was causing the error. In my case, my IDE linter wasn't giving me any hints either.

Qazzian
  • 684
  • 6
  • 9
0

The following helped me.

Delete all node_modules

rm -rf node_modules/

and then install

npm install
Pankaj Shinde
  • 3,361
  • 2
  • 35
  • 44