Syntax error on "=" NodeJs in Ubuntu 20.04 - node.js

I have developed a NodeJs(v10.19.0) server on windows.
I now need to transfer it to a linux server running Ubuntu 20.04
When I try to start the server, I have a syntax error on a "=".
Here's the complet error:
/puppeteer/scraping-bot.js:6
static websiteRegex = /^(https?\:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(\/[\w\W]*)*$/gm
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/routes/scraping.js:1:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
[nodemon] app crashed - waiting for file changes before starting...
Here's the code that outputs the error:
class ScrapingBot {
static websiteRegex = /^(https?\:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(\/[\w\W]*)*$/gm
static phoneRegex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;
static addressRegex = /(([a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ'.]*\s)\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)*,)*\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)+,\s([\d]{5})\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']+/
...
}
I set up Git with nano if that helps...
I have already tried to replace the "=".

As you can see in here, static class fields are not supported as of Node 10 ->
https://node.green/#ES2022-features-static-class-fields
edit: #jonrsharpe also answered this

Related

why child process not support query session

hello guys I search a lot on the internet as well as I tried the below thing but this does not work I don't know why
const exec = require('child_process');
let p = exec.execSync("query session").toString();
can anyone tell me why the above line "query session" is not working other than this eg "tasklist","whoami" etc everything working fine
error throw like show below:
Error: Command failed: query session rpa-agent1
at checkExecSyncError (child_process.js:629:11)
at Object.execSync (child_process.js:666:13)
at TestScreen.execute (C:\Users\Public\production_rpa_agent\action-
paths\testscreen\index.js:39:21)
at Object.<anonymous> (C:\Users\Public\production_rpa_agent\action-paths\testscreen\index.js:67:4)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
query session is a window command used for getting rdp login user.

nodemon or nodemon index.js not working on ubuntu 16.04

I am trying to run my server automatically after every push, do not want to restart every time on ubuntu instance 16.04
/usr/local/lib/node_modules/nodemon/lib/monitor/run.js:356
let sig = signal.replace('SIG', '');
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/lib/monitor/index.js:2:8)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
having this error, can anyone tell what is the problem?
Thanks budy #developerKumar and sorry for late reply.
you gave me a hint I simply upgrade my node version and its working.

Node js script not starting up, async * Unexpected Token

I am trying to run my node script with node . on Ubuntu 18.04
It worked successfully on previous machine. This is a new setup and running into this error.
/var/www/html/node_bot/node_modules/discord.js/src/structures/interfaces/Collector.js:203
async *[Symbol.asyncIterator]() {
^
SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/www/html/node_bot/node_modules/discord.js/src/structures/MessageCollector.js:3:19)
My node version is v8.10.0 on all accounts including root.
I have tried chowning the files to root and running from root, same error.
Am I missing a package or something? Thanks
Use a newer node version.
From library documentation
https://github.com/discordjs/discord.js
Installation
Node.js 10.2.0 or newer is required.
Updated to node v10.18.1 and it works.

throw new TypeError('The super constructor to "inherits" must not ' +

I am trying to build my nodejs application. but i am always getting this error.
util.js:988
throw new TypeError('The super constructor to "inherits" must not ' +
^
TypeError: The super constructor to "inherits" must not be null or undefined
at Object.inherits (util.js:988:11)
at Object.<anonymous> (D:\CIDE-Backend\CIDE-BACKEND\node_modules\zetta\node_modules\spdy\lib\spdy\connection.js:86:6)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\CIDE-Backend\CIDE-BACKEND\node_modules\zetta\node_modules\spdy\lib\spdy.js:20:19)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
[nodemon] app crashed - waiting for file changes before starting...
i followed this solution but still i am getting same error.
my node version is 8.4.0
my npm version is 5.5.1
Can you tell me how can i solve this error.?
Your dependency zetta is including an ancient version of spdy which is not compatible with you current version of Node. There is currently an open issue on zetta's github about this, which has a work around:
process.EventEmitter = require('events').EventEmitter
const zetta = require('zetta')
Your mileage may vary on that hack, I have not tested it myself. Alternatively, you could wait for the zetta team to fix their dependency or downgrade your node installation.

ReferenceError: require is not defined (node.js)

I'm trying to run a node.js script from my node.js server. The problem is that the modules I import with require () do not work anymore while all the modules and files are in the same folder.
var mysql = require('mysql');
^
ReferenceError: require is not defined
at evalmachine.<anonymous>:3:13
at ContextifyScript.Script.runInThisContext (vm.js:25:33)
at Object.runInThisContext (vm.js:97:38)
at Object.<anonymous> (D:\wamp\www\node_server\test_server.js:8:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
Thank you in advance,
I had a similar problem - server-side nodejs thinking that require is not defined.
It turns out the line "type": "module" in my package.json was causing this error, and once I removed that require worked as expected.

Resources