0

I'm having a problem with my node JS code, i'm getting the error:

/root/dev/remote/remote.js:43
.on('connection', async (socket) => {
                        ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)
Launching Chromium
[486:527:0824/012248.628260:ERROR:bus.cc(394)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")

(google-chrome:486): LIBDBUSMENU-GLIB-WARNING **: 01:22:49.591: Unable to get session bus: Unknown or unsupported transport ?disabled? for address ?disabled:?
[486:610:0824/012250.491318:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[486:610:0824/012250.493116:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[486:610:0824/012250.497596:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
^C[509:509:0824/012302.391101:ERROR:x11_util.cc(109)] X IO error received (X server probably went away)
[486:486:0824/012302.391250:ERROR:chrome_browser_main_extra_parts_x11.cc(62)] X IO error received (X server probably went away)

However, the syntax to this is perfectly fine.

I've tried reinstalling node/using different versions but im not sure if it's something to do with that in the first place.

here's the remote.js (there's more, this is just the relevant area)

const server = require('http').createServer();
const socketIO = io(server);

socketIO
.on('connection', async (socket) => {
    socket
    .use((socket, next) => {
        if(true) return null;
        if(socket.handshake.query && socket.handshake.query.token){
            jwt.verify(socket.handshake.query.token, 'SECRET_KEY', (err, decoded) => {
                if (err) return next(new Error('Authentication error'));
                socket.decoded = decoded;
                next();
            });
        }else{
            next(new Error('Authentication error'));
        }
    })

Does anyone know what this is? im trying to display my chromium instance on my Centos 7 VPS into a browser and control it through browser.

ilovejq
  • 179
  • 1
  • 3
  • 11
  • What version of node.js? That error looks like an older version that doesn't know about either `async` or fat arrow functions. You could try removing both (replace with classic function) and see if that gets you by that error. – jfriend00 Aug 24 '19 at 02:02
  • @jfriend00 im on node v6.17.1 ill try that now, but i don't think that will fix it :( – ilovejq Aug 24 '19 at 02:05
  • @jfriend00 i just realized my node is severely outdated, thanks to centos. Going to try to update or figure out how. – ilovejq Aug 24 '19 at 02:07
  • I don't think node.js v6 supports `async` without special command line flags. Definitely worth getting a much, much newer version of node.js if you want to use modern language features. – jfriend00 Aug 24 '19 at 02:07
  • @jfriend00 you're right! Thank you :) I updated and all errors gone! Thank you! – ilovejq Aug 24 '19 at 02:14
  • Possible duplicate of [SyntaxError: Unexpected token function - Async Await Nodejs](https://stackoverflow.com/questions/37815790/syntaxerror-unexpected-token-function-async-await-nodejs) – Sebastian Simon Aug 24 '19 at 03:46

1 Answers1

0

Your older node v6.17 won't support the async keyword by default (ES7 feature). There is a command line switch that might enable some of the newer features, but honestly that version is a bit old.

Since node.js is now up to v12 for a stable release, you probably want to upgrade to a newer node.js version if you want to use the most recent language features.

jfriend00
  • 683,504
  • 96
  • 985
  • 979