"SyntaxError: Unexpected Token" when running - javascript

A Photo Of The Code
I do not understand why it is not running, I keep receiving this error
});
^
SyntaxError: Unexpected token }
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:193:16)

Even if you didn't respect the "don't post images" rule, I'll try giving you an answer.
I see in the image that at line 30 you have an else that is not closed, and the next character is a }, so it may be that causing the problem. You should write else {} in order to make the code run.
To avoid this kind of silly errors, try using something like ESLint: I see you're using Atom Editor, there's an atom package for that (link)

Related

Node cannot compile static initializer block [duplicate]

I've been looking at this error for a long time and I just cannot wrap my head around it.
Here's the code:
class Instance {
static {
}
}
module.exports = Instance;
That is all there is. The class was full of stuff but I deleted them all because they are irrevelant. It's giving the same error with or without them.
The error:
static {
^
SyntaxError: Unexpected token '{'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.<anonymous> (path\to\project\index.js:1:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
I've used static constructors in the past and testing the same code somewhere else seems to work so I dont understand what the issue is here. Please help me.
SOLUTION: Updated Node to 16.13.1 and it now works. 16.7.0 wasnt enough.
It is supported by Node 17.3.0. It is an ES2022 feature. This https://node.green/#ES2022 is a nice link to find ES feature compatibility in Nodejs. You will have to download the current version of Nodejs which is 17.3.0.

I get throw new ERR_SERVER_ALREADY_LISTEN(); when I try to run my program with node.js. Am I closing it wrong?

recently I have been using node.js to code something that creates a server on localhost, and when I'm done running it with node, I press control+C to stop it. Then I made some modifications, attempted to run it again, and I get this:
net.js:1399
throw new ERR_SERVER_ALREADY_LISTEN();
^
Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
at Server.listen (net.js:1399:11)
at Object.<anonymous> (C:\Users\mmein\OneDrive\Desktop\pywork\socketthing.js:16:12)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'ERR_SERVER_ALREADY_LISTEN'
}
Did I close my program wrong and its still running in the background? If so, how do I close it?
Thanks in advance if you help.

How to track down an unexpected token in JSON? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
undefined:13
]
^
SyntaxError: Unexpected token ] in JSON at position 267
I have found many similar questions and I assume the problem is that JSON.parse returns incorrect data with an extra ] symbol. Probably HTML instead of JSON or something. But the problem is that I can't figure out how to track down where exactly the problem comes from? I have multiple js files with many JSON.parse included. The answer should be in my error message but I can't figure out where to look at. Line 267 is definitely a wrong answer because it is an empty line in all my files. Thanks.
Full error:
undefined:13
]
^
SyntaxError: Unexpected token ] in JSON at position 267
at JSON.parse (<anonymous>)
at mybp (eval at <anonymous> (/Users/apple/Desktop/UTESTTWO/app/bp.js:39:1), <anonymous>:109:25)
at getaccountdata (/Users/apple/Desktop/UTESTTWO/app/bp.js:64:1)
at Object.<anonymous> (/Users/apple/Desktop/UTESTTWO/app/bp.js:351:1)
at Module._compile (module.js:653:30)
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 Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/apple/Desktop/UTESTTWO/automatic.js:1:63)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
One option is a bit like playing 21 questions. Remove or comment out calls to half of your code and see if the error persists. That will help you tell which half contains the error. Once you know which half it is, then split the code in that half again. Repeat the process and keep reducing your code in half until you narrow it down to the section that contains the error.
When you don't have much else to go on you sometimes must resort to reduction techniques like this to narrow your scope.

Does the setMaxListeners warning affect my discord.js code?

As I was restarting my code using nodemon, I got the following warning:
(node:11576) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit.
Code: to Ubuntu Pastebin Link
I believe this is caused by the fact that I have >10 client.on(); scripts. Here's my logic for it: if client is what runs the EventEmitter, and each client.on is a Listener, then there would be over 10 listeners.
I've tried just putting emitter.setMaxListeners(Infinity), but I get the following error (note that line numbers may not be accurate):
/home/discord/Desktop/channel.js:9
emitter.setMaxListeners
^
ReferenceError: emitter is not defined
at Object.<anonymous> (/home/discord/Desktop/channel.js:9:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at Startup (internal/bootstrap/node.js:283:19)
at bootsrapNodeJSCore (internal/bootstrap/node.js:743:3)
[nodemon] app crashed - waiting for file changes before starting...
What should I add to fix this? I'm worried some of my client.on subscripts may not work run.
In your case emitter is your Discord.js client.
So you can use this to allow Infinity listeners:
client.setMaxListeners(0);
But this is not advisable because there's probably a memory leak somewhere in your code.

libsass bindings not found. Try reinstalling node-sass?

Im trying to create an offline app following this tutorial here:
http://rafaelquintanilha.com/offline-app-with-meteor-and-cordova/
But whenever I get to the:
meteor run android-device
I get an error:
=> Started proxy.
=> Started MongoDB.
=> Errors prevented startup:
While loading plugin compileScss from package fourseven:scss:
/home/bryam/.meteor/packages/fourseven_scss/.2.1.1.1l0pytj++os.linux.x86_64+web.browser+web.cordova/plugin.compileScss.os.linux.x86_64/npm/node_modules/meteor/compileScss/compileScss/node_modules/node-sass/lib/index.js:22:11:
libsass bindings not found. Try reinstalling node-sass? at
getBinding
(/home/bryam/.meteor/packages/fourseven_scss/.2.1.1.1l0pytj++os.linux.x86_64+web.browser+web.cordova/plugin.compileScss.os.linux.x86_64/npm/node_modules/meteor/compileScss/compileScss/node_modules/node-sass/lib/index.js:22:11)
at Object.
(/home/bryam/.meteor/packages/fourseven_scss/.2.1.1.1l0pytj++os.linux.x86_64+web.browser+web.cordova/plugin.compileScss.os.linux.x86_64/npm/node_modules/meteor/compileScss/compileScss/node_modules/node-sass/lib/index.js:188:23)
at Module._compile (module.js:409:26) at
Object.Module._extensions..js (module.js:416:10) at Module.load
(module.js:343:32) at Module.Mp.load
(/home/bryam/.meteor/packages/meteor-tool/.1.4.0-1.13j49n2++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/reify/node/runtime.js:16:23)
at Function.Module._load (module.js:300:12) at Module.require
(module.js:353:17) at require (internal/module.js:12:17) at
Object. (/tools/isobuild/bundler.js:1565:22) at
Object.require (/tools/isobuild/bundler.js:1542:11) at
packages/compileScss/plugin/compile-scss.js:2:1 at
:151:4 at :158:3
=> Your application has errors. Waiting for file change.
I have tried everything that I found on google and I still keep getting the same error, somebody know how to fix this?

Categories