That { lost in thin air

/rbd/pnpm-volume/35fc3320-2bd9-4943-8b77-fecb6a001ecd/node_modules/.registry.npmjs.org/discord.js/12.3.1/node_modules/discord.js/src/client/Client.js:41
} catch {
^
SyntaxError: Unexpected token {

ok the error may seem simple to understand but I can’t find it inside my code, even reducing it to the bone, it keeps giving me error:

these is my package.json:

{
“name”: “bothouse”,
“version”: “0.1.1”,
“description”: “Comune per i BOT EXCP”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“express”: “^4.17.1”,
“discord.js”: “^12.3.1”,
“node”: “^14.8.0”
},
“engines”: {
“node”: “8.x”
},
“repository”: {
“url”: “the correct URL”
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”,
“discord”
]
}

and these is the simple erver.js:

const fs = require(“fs”); // utilizza FS.js File system dll
const Discord = require(“discord.js”); // Utilizza la libreria di discord.js
const RALFclient = new Discord.Client(); // definisco una variabile come client di discord
//const NOLANclient = new Discord.Client(); // definisco una variabile come client di discord
//const TRIGGERclient = new Discord.Client(); // definisco una variabile come client di discord
const XMLHttpRequest = require(“xmlhttprequest”).XMLHttpRequest;

RALFclient.login(process.env.TOKEN);
//NOLANclient.login(process.env.NOLANTOKEN);
//TRIGGERclient.login(process.env.TRIGGERTOKEN);

Hey LordMorotok, welcome!

It looks like the problem is not in your code, but that your Glitch is having trouble using that version of discord.js, as the syntax error is in node_modules/discord.js/src/client/Client.js

(I’m not a discord expert)

What I’d recommend is that you check what node version you have on your project by opening the terminal and running node -v

Can you tell us what project you remixed from originally?

Cheers!

Hey @LordMorotok,

Try changing the Node version in your package.json to 12.x.

"engines": {
 "node": "12.x" 
},

Node.js won’t usually work with these strings: “”,
So I fixed it up for you!

{
  "name": "bothouse",
  "version": "0.1.1",
  "description": "Comune per i BOT EXCP",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "discord.js": "^12.3.1",
    "node": "^14.8.0"
  },
  "engines": {
    "node": "8.x"
  },
  "repository": {
    "url": "the correct URL"
  },
  "license": "MIT",
  "keywords": ["node", "glitch", "express", "discord"]
}

(Well, at least the last time I tried here)

I think it’s Discourse manipulating double quotes…?

1 Like

But the error does not seem to be coming from the package.json!

I’m saying that because when I validated the package.json at [jslint.com], Due to the Syntax of the package.json, it probably picked the { out of thin air.

Screenshot:

1 Like

Thanks to all of the tips.

my node version is 8.15.1

the questionde of the quotes is just a copy paste problem, in the file they are correct.

When I do this JSON File, Glitch can’t validate it.

First JSON File
{
“//1”: “simple BOTs house”,
“//2”: “https://docs.npmjs.com/files/package.json”,
“//3”: “updating this file will download and update your packages”,
“name”: “bothouse”,
“version”: “0.1.1”,
“description”: “Comune per i BOT EXCP”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“express”: “^4.17.1”,
“discord.js”: “^12.3.1”,
“node”: “^14.8.0”
},
“engines”: {
“node”: “8.x”
},
“repository”: {
“url”: “https://glitch.com/edit/#!/tenente-ralf”
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”,
“discord”
]
}

When I do the revised JSON file, It validates

Revised JSON File
{
  "name": "bothouse",
  "version": "0.1.1",
  "description": "Comune per i BOT EXCP",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "discord.js": "^12.3.1",
    "node": "^14.8.0"
  },
  "engines": {
    "node": "8.x"
  },
  "repository": {
    "url": "the correct URL"
  },
  "license": "MIT",
  "keywords": ["node", "glitch", "express", "discord"]
}

Also, the JS file was invalid because of those quotes:

1st Main JS File
const fs = require(“fs”); // utilizza FS.js File system dll
const Discord = require(“discord.js”); // Utilizza la libreria di discord.js
const RALFclient = new Discord.Client(); // definisco una variabile come client di discord
//const NOLANclient = new Discord.Client(); // definisco una variabile come client di discord
//const TRIGGERclient = new Discord.Client(); // definisco una variabile come client di discord
const XMLHttpRequest = require(“xmlhttprequest”).XMLHttpRequest;

RALFclient.login(process.env.TOKEN);
//NOLANclient.login(process.env.NOLANTOKEN);
//TRIGGERclient.login(process.env.TRIGGERTOKEN);

Then I revised it and Glitch was ok

Revised MainJS
const fs = require("fs"); // utilizza FS.js File system dll
const Discord = require("discord.js"); // Utilizza la libreria di discord.js
const RALFclient = new Discord.Client(); // definisco una variabile come client di discord
//const NOLANclient = new Discord.Client(); // definisco una variabile come client di discord
//const TRIGGERclient = new Discord.Client(); // definisco una variabile come client di discord
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

RALFclient.login(process.env.TOKEN);
//NOLANclient.login(process.env.NOLANTOKEN);
//TRIGGERclient.login(process.env.TRIGGERTOKEN);

Thanks everyone for the support!
This was a NODE version issue.
I solved it by reinstalling it and writing the correct version in the package.

1 Like

Thought it might be! Well done solving it yourself :+1: