0
/home/runner/SR12/index.js:83
            lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut ? startAsrbot() : console.log('Koneksi Terputus...')
                                 ^

SyntaxError: Unexpected token '.'

I getting an error when running the program in repl.it, even though on my personal laptop the application runs smoothly but for some reason when I run it on repl.it it gets an error like the text above.

I've made sure there's nothing wrong, but when I run it in repl.it it gets an error, here's my code:

    require('./config')
    const { default: makeWASocket, useSingleFileAuthState, DisconnectReason, generateForwardMessageContent, prepareWAMessageMedia, generateWAMessageFromContent, generateMessageID, downloadContentFromMessage } = require("@adiwajshing/baileys-md")
    const { state, saveState } = useSingleFileAuthState(`./${sessionName}.json`)
    const pino = require('pino')
    const fs = require('fs')
    const chalk = require('chalk')
    const fetch = require('node-fetch')
    const FileType = require('file-type')
    const http = require('http');
    const express = require('express');
    const { imageToWebp, videoToWebp, writeExifImg, writeExifVid } = require('./lib/exif')
    const { smsg, isUrl, generateMessageTag } = require('./lib/myfunc')
    const app = express();
    app.use(express.json());
    
    app.use('/', function(req, res) {
        res.send('node-ex-api works!');
    });
    
    const server = http.createServer(app);
    const port = 3000;
    server.listen(port);
    
    console.debug('Server listening on port ' + port);
    
    global.api = (name, path = '/', query = {}, apikeyqueryname) => (name in global.APIs ? global.APIs[name] : name) + path + (query || apikeyqueryname ? '?' + new URLSearchParams(Object.entries({ ...query, ...(apikeyqueryname ? { [apikeyqueryname]: global.APIKeys[name in global.APIs ? global.APIs[name] : name] } : {}) })) : '')
    
    
    async function startAsrbot() {
        const asrbot = makeWASocket({
            logger: pino({ level: 'silent' }),
            printQRInTerminal: true,
            browser: ['Asrbot Multi Device','Safari','1.0.0'],
            auth: state
        })
    
        asrbot.ev.on('messages.upsert', async chatUpdate => {
            //console.log(JSON.stringify(chatUpdate, undefined, 2))
            try {
            mek = chatUpdate.messages[0]
            if (!mek.message) return
            mek.message = (Object.keys(mek.message)[0] === 'ephemeralMessage') ? mek.message.ephemeralMessage.message : mek.message
            if (mek.key && mek.key.remoteJid === 'status@broadcast') return
            if (!asrbot.public && !mek.key.fromMe && chatUpdate.type === 'notify') return
            if (mek.key.id.startsWith('BAE5') && mek.key.id.length === 16) return
            m = smsg(asrbot, mek)
            require("./asrbot")(asrbot, m, chatUpdate)
            } catch (err) {
                console.log(err)
            }
        })
    
        asrbot.ev.on('group-participants.update', async (anu) => {
            console.log(anu)
            try {
                let metadata = await asrbot.groupMetadata(anu.id)
                let participants = anu.participants
                for (let num of participants) {
                    // Get Profile Picture User
                    try {
                        ppuser = await asrbot.profilePictureUrl(num, 'image')
                    } catch {
                        ppuser = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
                    }
    
                    // Get Profile Picture Group
                    try {
                        ppgroup = await asrbot.profilePictureUrl(anu.id, 'image')
                    } catch {
                        ppgroup = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
                    }
    
                    if (anu.action == 'add') {
                        asrbot.sendMessage(anu.id, { image: { url: ppuser }, contextInfo: { mentionedJid: [num] }, caption: `Welcome To ${metadata.subject} @${num.split("@")[0]}` })
                    } else if (anu.action == 'remove') {
                        asrbot.sendMessage(anu.id, { image: { url: ppuser }, contextInfo: { mentionedJid: [num] }, caption: `@${num.split("@")[0]} Leaving To ${metadata.subject}` })
                    }
                }
            } catch (err) {
                console.log(err)
            }
        })
        
        // Setting
        asrbot.public = true
    
        asrbot.ev.on('connection.update', async (update) => {
            const { connection, lastDisconnect } = update
            if (connection === 'close') {
LINE 83 >>                lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut ? startAsrbot() : console.log('Koneksi Terputus...')
            }
            console.log('Koneksi Terhubung...', update)
        })

I have marked the error line (at the bottom of my script)

The version of node and npm I'm using: node : v14.17.3, npm : 6.14.13

The version of node and npm using in Replit: node : v12.22.6, npm : 6.14.15

Paul Wheeler
  • 18,988
  • 3
  • 28
  • 41
Mr ASR
  • 1
  • 1
  • 5
    Optional chaining was not introduced until Node 14, which would explain why you can't use it on Repl.it, which is still running v12.22.6. As such this is a duplicate of [How to use optional chaining in Node.js 12](https://stackoverflow.com/questions/59574047/how-to-use-optional-chaining-in-node-js-12) – esqew Jan 05 '22 at 12:28
  • @esqew Does that mean when I want to run my program on another device, I have to use the same version? – Mr ASR Jan 05 '22 at 12:32
  • 2
    You don't need to use the *same* version. Wherever you want to run anything, you'll need to ensure you're using a version of your runtime that supports the language features you want to use. – esqew Jan 05 '22 at 12:33
  • Ugh, people are so hasty with the close votes. I was about to post a nice write up of dealing with this specifically on Replit.com – Paul Wheeler Jan 05 '22 at 20:58
  • Should have been an answer: If you want to use the optional chaining operator on Replit.com you can either use the [Node.js 16 Template](https://replit.com/@RoBlockHead/NodeJS-16?v=1) when creating your repl, or you can use [babel](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining) to run and/or build your ES2020 code. Here's [an example](https://replit.com/@KumuPaul/Node12-Optional-Chaining) of using optional chaining on Replit.com by configuring your package to use bable. – Paul Wheeler Jan 05 '22 at 20:58

0 Answers0