How to solve this 'SyntaxError: Invalid regular expression' in pm2 - node.js

I install node.js with pm2, all install fine but when i try to do pm2 monit give me this error.
$ pm2 monit
/home/node/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/node_modules/fast-printf/dist/src/tokenize.js:4
const TokenRule = /(?:%(?<flag>([+0-]|-\+))?(?<width>\d+)?(?<position>\d+\$)?(?<precision>\.\d+)?(?<conversion>[%BCESb-iosux]))|(\\%)/g;
^
SyntaxError: Invalid regular expression: /(?:%(?<flag>([+0-]|-\+))?(?<width>\d+)?(?<position>\d+\$)?(?<precision>\.\d+)?(?<conversion>[%BCESb-iosux]))|(\\%)/: Invalid group
at Object.<anonymous> (/home/node/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/node_modules/fast-printf/dist/src/tokenize.js:4:19)
at Module._compile (module.js:652:30)
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> (/home/node/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/node_modules/fast-printf/dist/src/createPrintf.js:5:20)
at Module._compile (module.js:652:30)
I tried servers nodejs version and always give me this error.

If you paste your regular expression into a regex sandbox, like this one:
https://regex101.com/r/GkwWH2/1
You'll see that it doesn't show any syntax errors.
That would make me suspect that you're running a back-level version of Node JS. And in fact, if you look at your stack trace, you see that you are running Node 8.11.3
at Object.<anonymous> (/home/node/.nvm/versions/node/v8.11.3/lib/node_modules/pm2/node_modules/fas
That regular expression is using features (such as named capture groups) that did not come into Node.js until Node v10.*.
I suggest you update to the latest LTS version of Node, version 14.*: from your stack trace it would appear that you're using NVM, so it should be a simple matter of
sudo nvm install lts/fermium
should do it.

Related

Nodejs "SyntaxError: Unexpected token ."

I'm trying to run a Bitcoin insight explorer (https://www.dgbwiki.com/index.php?title=Running_your_own_Insight_explorer). Using node v0.10.48 but I get this error (couldn't find the same problem over the internet):
digibyte#derecha-virtual-machine:~/insight$ /home/digibyte/.nvm/v0.10.48/bin/node ~/insight/node_modules/insight-bitcore-api/util/sync.js -D -v --rpc
/home/digibyte/insight/node_modules/insight-bitcore-api/node_modules/async/dist/async.js:52
function apply(fn, ...args) {
^
SyntaxError: Unexpected token .
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/digibyte/insight/node_modules/insight-bitcore-api/lib/HistoricSync.js:5:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
The offending line 52 is in this function:
function apply(fn, ...args) { // <- line 52
return (...callArgs) => fn(...args,...callArgs);
}
It looks ok to me I don't know why node gives an error.
Node.js 0.10.48 doesn't support the spread operator. The first Node.js version to support the spread operator was 5, but it's quite outdated and isn't maintained anymore. If you're already upgrading, I'd upgrade to one of the newer version still supported under LTS.
According to https://node.green/#ES2015-syntax-rest-parameters, node v0.10.48 does not support rest parameters (...args).
You should use a newer version of node (at least v6.4.0 as default support, or at least v4.9.1 with --harmony flag (node --harmony))
Apply takes an array as the second argument. Here, the spread operator (...) is laying out the elements, and thus you don't pass an array into the function, but basically comma separated arguments.
Try using .call instead of .apply, or pass args instead of ...args.

PM2 - SyntaxError: Block-scoped declarations not yet supported outside strict mode

I'm currently installing a NodeJS service on an Ubuntu server. The application is written in coffeescript and runs fine on it's own. This is how I setup the project:
cd ~/test-project
nvm use v4.9.1
npm install
pm2 start index.js
However when I try to start it using pm2 i get the error below:
/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/node.js:132
let val = process.env[key];
^^^
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:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/index.js:9:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
And after doing some testing it seems that this error occurs no matter what script I start with pm2 so there must be something that isn't configured correctly..
I don't know if it matters but the script I am trying to run needs node v4.9.1 so I am using NVM to use that version, it seems to me that it is trying to run pm2 with that same node version somehow?
Any input is greatly appreciated as I've been stuck on this for way too long!!
I had the same issue on node version 4.x,
Downgraded the pm2 and it worked.
npm uninstall -g pm2
npm install -g pm2#3.0.4
'use strict';
Add above line of code to first line of the script file. let is used when you want a variable to be scoped to a block which is supported in strict mode in node v4.
See the documentation for more details.
#Vishnu Sing this is the complete output. The index.js file looks like this:
console.log('Hello World');
ubuntu#ip-172-31-32-5:~/test-project$ nano index.js
ubuntu#ip-172-31-32-5:~/test-project$ node -v
v10.15.3
ubuntu#ip-172-31-32-5:~/test-project$ sudo pm2 start index.js
/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/node.js:132
let val = process.env[key];
^^^
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:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/index.js:9:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
ubuntu#ip-172-31-32-5:~/test-project$

Installation problems with CodeceptJS on Ubuntu

I was settings up a new system to use CodeceptJS and have hit an issue. I followed these notes, but just get an error when trying to run codeceptjs. The error is...
codeceptjs
/usr/local/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/mocha_factory.js:6
let mocha;
^^^
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:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/container.js:5:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
My node.js and npm is installed globally via normal apt-get and npm -g
System info...
Ubuntu 17.04 x86_64
nodejs: 4.7.2
npm: 4.5.0
bash 4.4.5
Does anyone know the cause of this issue or how to get around it?
Just as an update, thanks to artem for the note on 'use strict'; I added that to the top of node_modules/codeceptjs/lib/mocha_factory.js and that, I think, got me past the initial problem. However I now seem to be hitting an issue in node_modules/codeceptjs/lib/output.js. The error is...
codeceptjs
/usr/local/lib/node_modules/codeceptjs-nightmare/node_modules/codeceptjs/lib/output.js:139
function print(...msg) {
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/codeceptjs-nightmare/node_modules/codeceptjs/lib/event.js:3:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
...I've tried a few things to resolve this, adjusting the print function there, but with no luck yet.
This seems to be the same with the codeceptjs-nightmare and codeceptjs-webdriverio meta-packages.
I'd be grateful of any ideas, suggestions or alternatives anyone has.
Your second issue is because of an outdated Node version. The spread operator (the ... error that you're seeing) is supported in Node 5.12.0 and later: http://node.green/#ES2015-syntax-spread-------operator
I'm not sure what the best way for you to upgrade is with Ubuntu, but that should solve your issue.

unable to install meanjs on linux mint

it has been one week now that i was trying to install meanjs stack and had no success.
Everytime I follow some tutorial and get errors. Now I end up with many issues, too much nodejs version, i dont know which one should be with what and why do karma not working ...etc
is there anyway to remove everything and install meanjs correctly and get it running successfully
+ WARNING: It is strongly recommended that you change sessionSecret config while running in production!
Please add `sessionSecret: process.env.SESSION_SECRET || 'super amazing secret'` to
`config/env/production.js` or `config/env/local.js`
/opt/mean/node_modules/connect-mongo/src/index.js:3
const Promise = require('bluebird');
^^^^^
error: uncaughtException: Use of const in strict mode. date=Mon Jul 18 2016 19:15:59 GMT+0400 (GST), pid=29602, uid=1000, gid=1000, cwd=/opt/mean, execPath=/usr/local/bin/node, version=v0.10.33, argv=[node, /opt/mean/server], rss=47960064, heapTotal=35267072, heapUsed=18951416, loadavg=[0.5966796875, 0.453125, 0.66748046875], uptime=4058.491096953
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/opt/mean/node_modules/connect-mongo/index.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/opt/mean/config/lib/express.js:12:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
below is my system config
Linux Mint 17.2 64-bit
NodeJS v0.10.33
npm 1.4.28
bower 1.7.9
mongodb v3.0.12
Can anyone please help me, I want to get started.
I haven't dug into it, but I'm guessing the version of node you have doesn't support the 'const' keyword. 0.10.x is a (fairly) old version of node; have you considered upgrading to one of the versions that has ES 6 native support?

Node.js - Module Version Mismatch on Linode Server

I am trying to deploy a node app on Linode (Ubuntu 12.04) while following this guide from Node Knockout: http://blog.nodeknockout.com/post/9300619913/countdown-to-ko-14-deploying-your-node-js-app-to
I have no problems running the server as root, but when trying to start the server as the "deploy" user using sudo start node, I get this error:
/home/deploy/app/source/node_modules/bcrypt/node_modules/bindings/bindings.js:79
throw e
^
Error: Module version mismatch. Expected 11, got 1.
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/home/deploy/app/source/node_modules/bcrypt/node_modules/bindings/$
at Object.<anonymous> (/home/deploy/app/source/node_modules/bcrypt/bcrypt.js:1:$
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I have tried recompiling bcrypt using make clean then make since I thought my module version was incompatible with my version of node (v0.8.18), but that does not seem to be the case since I can start the server as root with no problem. I feel as though the problem lies in how I set up the deploy user, but I am not sure how to proceed.

Resources