-1
    /home/discord/project/bloodmoon/node_modules/discord.js/src/client/Client.js:42
    } catch {
            ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/discord/project/bloodmoon/node_modules/discord.js/src/index.js:8:11)

i'm interested in developing discord bot. so i tried it. first, it works. but, i moved the server and i setted it. and it not works! please give advise to me.

(please understand i can't write a English essay well. sorry)

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
이연준
  • 41
  • 5
  • 1
    Can you share your **code** please? This looks like a **sytax error** and we won't be able to help with only the error message :D – Toasty Jun 30 '21 at 11:29
  • it is not a sytax error! " first, it works. but, i moved the server and i setted it. and it not works!" – 이연준 Jul 03 '21 at 04:22

1 Answers1

1

If you check the discord.js source code, you can see that they're trying to silently ignore if there is an error when their code requires the worker_threads module. They simply omit the usual (error) part after catch:

try {
  // Test if worker threads module is present and used
  data = require('worker_threads').workerData || data;
} catch {
  // Do nothing
}

However, it only works in newer versions of JavaScript and older ones will throw a SyntaxError. So, you must be using an older version of Node, because optional catch binding is only available in Node.js v10+.

The following is an example in Node v8:

// using Node v8
try { error } catch { console.log('oops') }

⬇ result ⬇

try { error } catch { console.log('oops') }
                    ^

SyntaxError: Unexpected token {

While it just works fine in Node v10+:

// using Node v16
try { error } catch { console.log('oops') }

⬇ result ⬇

oops

To solve this, you need to update your Node version to at least v12, as mentioned in the discord.js docs:

v12 requires Node 12.x or higher, so make sure you're up-to-date. To check your Node version, use node -v in your terminal or command prompt, and if it's not high enough, update it! There are many resources online to help you with this step based on your host system.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57