Composer Rest Server error "async *__getField() {" - node.js

I have followed this (https://medium.com/coinmonks/build-a-insurance-application-with-hyperledger-composer-and-react-js-part-1-3ebe7ad54986) tutorial upto "create our REST API".
Now when i run following command
composer-rest-server -c admin#secure-phi -n never -u true -w true
I get following error
/home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server/node_modules/formdata-node/lib/FormData.js:206
async *__getField() {
^
SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
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. (/home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server/node_modules/#tim-lai/isomorphic-form-data/lib/index.js:2:18)
Is this a syntax related error or something else, and any way to fix this?
I found the error is related to generator not supported below node v8, but hyper-ledger-composer specifically requires node v8, so any work around to this?

It seems to be a version conflict between sub-dependencies in the graph.
Looks like the package 'g11n-pipeline' is requiring a different version of 'swagger-client' that pulls the dependency '#tim-lai/isomorphic-form-data'.
I did this workaround as it is a global package (we don't have access to the package-lock.json/package.json).
Since you've installed with NPM (npm i -g composer-rest-server):
cd /home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server
npm install swagger-client#3.9.0
rm -rf node_modules/g11n-pipeline/node_modules/swagger-client

Related

How to solve this 'SyntaxError: Invalid regular expression' in pm2

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.

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.

Use of const in strict mode (Node.js and Mongoose)

I have seen this question asked many times around here, but none of the solutions seem to fit my case.
I am using Node.js to access a MongoDB database. I am using Mongoose library. All on Ubuntu 14.04.
When trying to run "nodejs myfile.js" I get this error:
const deprecationWarning = 'The `MONGOOSE_DRIVER_PATH` global property is '
^^^^^
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.<anonymous> (/root/nodejs/node_modules/mongoose/index.js:9:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
The main solution I found is upgrading Node.js with this commands:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
but the result after is the same.
Also tried to run it with 'harmony' flag:
nodejs --harmony myfile.js
...but I still get similar errors like:
for (const key of ['Schema', 'model']) {
^^
SyntaxError: Unexpected identifier
My dependencies in package.json are:
"dependencies": {
"express": "~4.17.1",
"mongoose": "~5.7.5"
}
And my Node.js version is v0.10.25
It seems I don't get to find the correct combination of packages or I am doing something else wrong. Any help would be appreciated.

Can't run node project after formatting my linux partition

As the title says, I formatted my linux partition where I used as web development environment. Mainly I used MongoDB and NodeJS and both of them are installed correctly. But when I try to execute my main.js I get an error log. It must be something extremely silly that I'm not reminded of. Any help is appreciated. Error log:
SyntaxError: Invalid or unexpected token
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
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 Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
Note that helpers.js is a node internal module.
Please download nodeJS command prompt for Linux or download by command
pacman -S nodejs npm
For More help : Visit the link
Node JS Installation Guide

Run a node package via node

I am trying to run a node package.
Technically, I can simply do ./node_modules/.bin/<package name> from my project's root folder, or even npx <package name> from any folder.
But I need to run node with a specific configuration of max-old-space-size set to 4096.
I am therefore trying to invoke it as follows:
node --max-old-space-size=4096 ./node_modules/.bin/<package name>
Which gives me the following error:
<root folder>\node_modules\.bin\<package name>:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I am pretty sure that this problem is due to the fact that I am running on Windows.
I did some research and came across this GitHub thread, which makes me even more confident that the problem is OS-related.
But I haven't been quite able to find a workable solution within this thread.
The only clue that I have found is by sc0ttwad3 from 12 days ago, suggesting to change this:
./node_modules/.bin/<package name>
To this:
./node_modules/<package name>/bin/<package name>.js
But there is no such js file in this path (in fact, there is not even a bin folder in this path).
Can anyone shed some light on this?

Resources