Search code examples
node.jsnpmbotsdiscorddiscord.js

SyntaxError: Unexpected token { while starting


Cause:

So, i was messing around with nodejs version (update) and i accidently made my nodejs program not work anymore. Problem with this is i dont remember what nodejs version i had before this. Atleast, it started happening when i did this.

Problem:

when i node app.js start my program, i get the following:

 $ node app.js
 /home/user/ftp/discordbot/schwi/app.js:3
 const {token} = require(path.join(__dirname, 'auth.json'));
       ^

 SyntaxError: Unexpected token {
     at exports.runInThisContext (vm.js:53:16)
     at Module._compile (module.js:374:25)
     at Object.Module._extensions..js (module.js:417:10)
     at Module.load (module.js:344:32)
     at Function.Module._load (module.js:301:12)
     at Function.Module.runMain (module.js:442:10)
     at startup (node.js:136:18)
     at node.js:966:3

Now i know that my code is correct considering it has been working before this.

PS: the { } is needed in other classes considering i use alot of variables. It just happend to be that in this token case its only 1 variable.

Code:

const path = require('path');
const Ononoki = require(path.join(__dirname, 'Ononoki.js'));
const {token} = require(path.join(__dirname, 'auth.json'));

start = function () {
    new Ononoki(token).init();
};

start();

To be honest i have no idea what the cause can be other than the version of node or something is wrong. Thank you for your replies.


Solution

  • Try removing node_modules and run npm install again in the root folder.

    $ rm -rf node_modules/

    $ npm update

    $ npm install