SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
could it be from running something other than the file you looked at? that’d would be consistent with there not being an obvious file name in the error. any idea what it could be running?
here’s a sample broken script, you can try running it
/* Simple Hello World in Node.js */
console.log(*);
(I’ve replaced the string with an asterisk)
this gets split up into tokens:
/* Simple Hello World in Node.js */ - a comment
console - an identifier
. - dot
log - an identifier
( - parenthesis
* - asterisk
) - parenthesis
; - semicolon
these are all tokens. certain patterns of tokens are meaningful, and you can run them as programs. not this sequence of patterns though. usually the asterisk is an operator for multiplying things (or possibly newfangled generator-related syntax) but there are no operands here—nothing to multiply together. it doesn’t have a meaning as a program.
usually the interpreter will tell you about where things went wrong, to the effect of “it made sense up until this point.” running this snippet gives:
/home/cg/root/650107a183006/main.js:2
console.log(*);
^
SyntaxError: Unexpected token '*'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
(that path being where tutorialspoint apparently saves your script in this tool) but see, it usually shows what file, what line, and in this case even a snippet of the code from that line
ah yeah, that’s the indication of where the syntax error is. referring to that ?. part right? that operator is added pretty recently. try running it in node 14+
/rbd/pnpm-volume/96899617-85c2-4e14-8a59-d1c695e21231/node_modules/discord.js/src/client/Client.js:509
throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
at Client._validateOptions (/rbd/pnpm-volume/96899617-85c2-4e14-8a59-d1c695e21231/node_modules/discord.js/src/client/Client.js:509:13)
at new Client (/rbd/pnpm-volume/96899617-85c2-4e14-8a59-d1c695e21231/node_modules/discord.js/src/client/Client.js:78:10)
Object. (/app/server.js:25:16)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: ‘ClientMissingIntents’
}