No certificate is generated in .hfc-key-store - node.js

I'm using an AWS Ubuntu 16.04 LTS following Hyperledger Fabric readthedocs tutorial. I followed steps in "Writing Your First Applications". When I ran "node enrollAdmin.js", a eCert and key material is expected to be generated in a hfc-key-store directory, but nothing is generated in this folder, which means the folder is still empty after running the command. I looked into the code in this js file, in lines 54-55, only two arguments are provided, but from the API from this link:https://jimthematrix.github.io/FabricCAClient.html#enroll__anchor, the fabric_ca_client.enroll function should receive three arguments, which means the third argument 'csr' is not given in the js file. Strangely, no error information is shown after running the command, and the only information i got from the terminal is "store path: $mypath/hfc-key-store".
Any one knows what the problem occurs?
Thanks

After I switch node version from 6.12.0 to 6.9.5, this issue is resolved. Looks like the node version has to be 6.9.x

Related

Cloud Functions Puppeteer cannot open browser

My setup in GCF:
install npm install --save puppeteer from project cloud shell
edit package.json like so:
{ "dependencies": { "puppeteer": "^19.2.2" } }
paste code from medium.com into index.js:
https://gist.githubusercontent.com/Alezco/b9b7ce4ec7ee7f208818e395225fcbbe/raw/8554acc8b311a10e272f5d1b98dce3400945bb00/index.js
deploy with 2 GB RAM, 0-3 instances, max 500s timeout
I get these errors after building or opening the URL:
Internal Server Error
Could not find Chromium (rev. 1056772). This can occur if either 1. you did not perform an installation before running the script (e.g. npm install) or 2. your cache path is incorrectly configured (which is: /workspace/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
When I run npm list both webdriver and puppeteer are installed. I suspect there is an issue this Path but I cannot figure out where it should lead.
I could then provide puppeteer.launch() with argument executablePath which might solve the problem.
I tried reinstalling puppeteer and changing configuration. No luck.
In addition to adding a .puppeteerrc.cjs per Kristofer's answer, I added a postinstall script in my package.json:
"scripts": {
...
"postinstall": "node node_modules/puppeteer/install.js"
},
This fixed the problem and I was able to deploy my Google Cloud Function. This is a temporary fix until issue #9128 is fixed.
I had the exact same issue and it seems to be related to this https://github.com/puppeteer/puppeteer/issues/9128
I'm using Firebase and don't have complete control over the build process when I deploy my functions but I still have access to the build logs. From the issue above, I realized I needed to handle the cache directory and the NPM version for this to work.
As far as I can tell the problem is that the build step installs the Chrome browser needed for Puppeteer in a cache directory outside of the final image that is used for the actuall function. In that context the error message makes more sence, it can't find the browser therefor it doesn't work.
I was using Node 14 in my cloud functions which used NPM 6.14.17 in the build steps. According to the issue you need to use NPM > 7 so I upgraded my function to use Node 16.
Then I added the .puppeteerrc.cjs from https://pptr.dev/guides/configuration/#examples when testing that locally it will add a .cache directory where the Chrome installation is. This has to be ignored when deploying the cloud function or the deplot will fail due to size.
In the firebase.json add:
"functions": {
"ignore": [
".cache"
]
},
The last step is pretty specific for Firebase and I'm not sure how this applies to your build steps etc. But this solved my issue that had the exact same error messages as you had. So double check the following:
NPM version in the build step, needs to beat least v.7 - Node 16 should do this.
Cache directory specified in the .puppeteerrc.cjs
It also looks like your using an old Puppeteer version, I used 19.3
I got this same (very missleading) error in my Puppeteer project which I run in Google Cloud Function. The issue was that Function was finishing (exiting) before the async Puppeteer script was finished.
Resolved this issue by changing the "await browser.close();" to a Promise and creating the response message in promise.then().
... only to hit next problem. My script is not downloading the csv file as expected. Works locally though...

How to add ICU data to Node.js in AWS Lambda?

My question is similar to an existing one, but I'm using webpack and thus don't even have a "node_modules" directory.
I've still tried the following environment variable settings without success:
NODE_ICU_DATA: 'node_modules/full-icu'
NODE_ICU_DATA: '/var/task/node_modules/full-icu/icudt58l.dat'
NODE_ICU_DATA: '/var/task/node_modules/full-icu/icudt60l.dat'
All without success, the lambdas simply refuse to start and a log message is show in CloudWatch:
/var/lang/bin/node: could not initialize ICU (check NODE_ICU_DATA or --icu-data-dir parameters)
I found very little about this problem on Google, which seems curious given that it should concern so many that are building internal apps on AWS lambda.
Make sure you're deploying the correct .dat file version into the directory defined by NODE_ICU_DATA. In my case, the correct file was icudt62l.dat when using the runtime nodejs10.x for my lambdas. If you're not deploying node_modules as part of your lambda, you can grab the correct .dat file and deploy that.
I ran into the same error message when upgrading the runtime version of some old lambdas from nodejs6.10 to nodejs10.x. In my case, the file icudt58l.dat (compatible with nodejs6.10) was deployed into the project root, and the value of NODE_ICU_DATA was . (i.e. the directory where my lambda executes, equivalent to /var/task/).
To get a compatible .dat file, I re-installed the full-icu package using the node version used by the lambdas:
npx -p node#10.x npm i full-icu
It's important that the version of the .dat file is correct for the runtime version your lambdas are using. Initially, I made the mistake of just running npm i full-icu using node version 10.0 but this installed the wrong version of the .dat file and I just got the same error message again.
Finally, I copied the file node_modules/full-icu/icudt62l.dat into the project root and deleted the old icudt58l.dat so that it ends up in /var/task/ where the lambda can find it when NODE_ICU_DATA=..

Trying to get MEAN maps to work on windows

I cloned this mean map that I watched on a azure mongodb video , and I did the same steps in the readme like they did
https://github.com/scotch-io/mean-google-maps
So
npm install
node server.js
// I didn't do any mongodb , as there is a config.js that is pointing at an amazon mongodb.
On the video they didn't do any mongodb locally
I see that in chrome console it throws an error with modernizr
#!/usr/bin/env node
That line is red squiggly , it that line causing the map to not load? Is that even going to work on a Windows 10 machine I'm running?
This error has nothing to do with mongodb.
The problem is the Modernizr link in the public/index.html (line 18) points to a script which is designed to be run server side.
The shebang #!/usr/bin/env node indicate a javascript file that must be run with Nodejs. Your browser can't run this kind of script.
It's looks like a confusion in bower dependency management.
(I think it is generaly not a good practive to include bower_components directory into git repository)
Maybe you can try to fix it by replacing the link with a cdnjs version of Modernizer:
https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js
Or just delete the line, you use a recent Chrome browser after all...

swagger-tools validate hangs when using external ref with absolute URLs

I am currently breaking down a swagger.json file following this guide: https://github.com/swagger-api/swagger-spec/blob/master/guidelines/REUSE.md
I made a mistake somewhere, and I would like to use the swagger-tools to find out where is my problem. When I run the tool, it just get stuck and doesn't produce any output.
I am using a localhost server, and my $ref are pointing to the localhost using absolute URLs such as:
"$ref": "http://localhost:8080/api-docs/v1/parameters.json#/myParameter"
I tried running using the file from the filesystem or served by the local server: none is working.
swagger-tools validate http://localhost:8080/api-docs/v1/swagger.json
However, if I shutdown the server and try to validate from the file system, the tools complains that it cannot resolve the references so somehow that proves that the file is parsed and swagger-tools tries to validate it.
Platform: Windows 7 Pro
Powershell
npm --version: 2.11.3
swagger-tools --version: 0.9.2
installed using npm -g install
I found the solution: the problem was coming from self-references in the definitions file that were using absolute URLs.
Using relative reference such as:
"$ref" : "#/myReference"
solved the issue and the swagger-tools validate is now working as expected.
I started suspecting something like that when I looked at the Node.js process and saw it was consuming 1.2 Go RAM and 25% CPU.

Basic Node.js setup on Windows

I'm trying to get node.js to run a sample script I've created. I'm using Windows. mysamplescript.js is in the same folder as the node.js executable. When I type in
node mysamplescript.js
I get ... returned on the next line. The docs for node aren't exactly stellar. Am I missing something?

Resources