graphicsmagic not installed in google cloud functions? - node.js

i m working in a project in firebase that uses graphics magic to convert images to pdf
it's working fine in local emulator
but doesnt in production
Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "./0" "./a4.pdf" this most likely means the gm/convert binaries can't be found at ChildProcess. (/workspace/node_modules/gm/lib/command.js:232:12) at ChildProcess.emit (events.js:198:13) at ChildProcess.EventEmitter.emit (domain.js:448:20) at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12) at onErrorNT (internal/child_process.js:415:16) at process._tickCallback (internal/process/next_tick.js:63:19)
knowing that in the cloud functions documentation they said that graphics magic is included in the environement
see : https://cloud.google.com/functions/docs/tutorials/imagemagick
Edit : gm requires installation (apt get install), i can't do that in cloud functions , cuz i dont have access to the machine.
i'm working now with pdfkit, its does the same job and doesnt require installation (requires npm install tho)

You are supposed to include gm on your dependencies. You can do so by running:
npm install gm
And have your dependencies look like:
"dependencies": {
"#google-cloud/storage": "^5.0.0",
"#google-cloud/vision": "^2.0.0",
"gm": "^1.23.1"
}
I just followed this documentation and it's working fine on Nodejs10 runtime.
UPDATE: It looks like there's an open issue on GitHub about this problem. I suggest you put a comment in there and provide detailed information similar to what the reporter did.

Related

Node / React app, packaging for Linux with pkg

I'm trying to package a node / react app as a native executable for each of Mac / Windows / Linux, using the node package 'pkg' (https://github.com/zeit/pkg/).
I can run the application with node on my machine without issue. I was also successfully able to use pkg to build and run the Mac version, and it works as expected. With the Linux version, the pkg build works (ie no errors), but I am getting an error when running the executable.
Error spawn /snapshot/IXmapsClient/node_modules/open/xdg-open ENOENT
(more detailed version below)
My understanding is that snapshot is the 'internal' directory created by pkg. The node module dir and file exists at ~/Dev/IXmaps/IXmapsClient/node_modules/open/ and has the correct permissions (along with all other required node_modules used by this application).
Details of what I'm working with:
Ubuntu 18.04 (I'm working on a Virtualbox VM with OSX underneath, in the event that that is relevant)
Node 10
Pkg 4.4.2 (pkg -t node10-linux-x64 server.js -o dist/linux/IXmapsClient --config package.json)
Full error message:
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /snapshot/IXmapsClient/node_modules/open/xdg-open ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (pkg/prelude/bootstrap.js:1317:13)
at startup (internal/bootstrap/node.js:320:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:659:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:659:3)
If anyone else encounters this issue, it looks to have been resolved. The author of the 'pkg' module has added support for the 'open' module with this commit: https://github.com/zeit/pkg/commit/db8487acd2d40af7b0cb1e63e133a707f93d725f

"Cannot read property 'match' of undefined" during Npm install

I encountered error during building Jenkins
Jenkins Log
Task :api:processResources
Task :api:classes
Task :web:nodeSetup
Task :web:npmSetup /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npm
-> /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/lib/node_modules/npm/bin/npm-cli.js
/var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npx
-> /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/lib/node_modules/npm/bin/npx-cli.js
npm#6.11.2 added 430 packages from 832 contributors in 6.837s
Task :web:npmInstall FAILED npm ERR! Cannot read property 'match' of undefined
npm ERR! A complete log of this run can be found in: npm ERR!
/var/lib/jenkins/.npm/_logs/2019-10-16T01_11_20_594Z-debug.log
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':web:npmInstall'.
Process 'command '/var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npm''
finished with non-zero exit value 1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 6.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 33s
/var/lib/jenkins/.npm/_logs/2019-10-16T01_11_20_594Z-debug.log
17 silly saveTree │ ├─┬ clean-css#4.2.1
17 silly saveTree │ │ └── source-map#0.6.1
17 silly saveTree │ ├── commander#2.17.1
17 silly saveTree │ └── he#1.2.0
17 silly saveTree └─┬ loader-utils#0.2.17
17 silly saveTree ├── big.js#3.2.0
17 silly saveTree ├── emojis-list#2.1.0
17 silly saveTree └── json5#0.5.1
18 verbose stack TypeError: Cannot read property 'match' of undefined
18 verbose stack at tarballToVersion (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:87:20)
18 verbose stack at inflatableChild (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:99:22)
18 verbose stack at BB.each (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:55:12)
18 verbose stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18 verbose stack at Object.gotValue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:155:18)
18 verbose stack at Object.gotAccum (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:144:25)
18 verbose stack at Object.tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18 verbose stack at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
18 verbose stack at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
18 verbose stack at Promise._settlePromiseCtx (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:606:10)
18 verbose stack at _drainQueueStep (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:142:12)
18 verbose stack at _drainQueue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:131:9)
18 verbose stack at Async._drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:147:5)
18 verbose stack at Immediate.Async.drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
18 verbose stack at runCallback (timers.js:810:20)
18 verbose stack at tryOnImmediate (timers.js:768:5)
19 verbose cwd /var/lib/jenkins/workspace/hds_v2_docker/web
20 verbose Linux 4.4.0-59-generic
21 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "install"
22 verbose node v8.16.0
23 verbose npm v6.9.0
24 error Cannot read property 'match' of undefined
25 verbose exit [ 1, true ]
Try removing your package-lock.json to see if that helps.
rm -rf package-lock.json
Edit: If the issue still persists, delete node_modules as well.
rm -rf node_modules
You have to remove both package-lock.json and node_modules/.
If you don't remove both, the problem will come back on the next npm install.
I had the same error when running npm install in my repo. I don't use Jenkins, but I found a generic approach to debugging (and ultimately resolving) this issue in NPM.
Open the npm debug log file that the cli provides you. (on Windows, under C:\Users\USERNAME\AppData\Roaming\npm-cache\_logs by default)
Look for the stack trace of the error, at the bottom of the file.
The first three lines of the error stack trace should be something like:
18 verbose stack TypeError: Cannot read property 'match' of undefined
18 verbose stack at tarballToVersion (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:87:20)
18 verbose stack at inflatableChild (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:113:22)
Open up the inflate-shrinkwrap.js file, and go to the line listed in stack-trace line #3 above.
Add this debugging code: (just before the line [in stack-trace] which calls tarballToVersion)
if (sw.version == null) {
console.error(`
NPM is trying to retrieve package "${name}" with version "undefined"!
Package location: ${(onDiskChild || {}).location}
Package parse error:`, (onDiskChild || {}).error);
}
Run npm install (or whatever command yields the error). You should see an output like this:
NPM is trying to retrieve package with version "undefined"!
Package location: /firebase-feedback/webpack-dev-middleware
Package parse error: [Error: ENOENT: no such file or directory, open 'C:\Root\Apps\#V\#Modules\firebase-feedback\Main\node_modules\webpack-dev-middleware\package.json'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Root\\Apps\\#V\\#Modules\\firebase-feedback\\Main\\node_modules\\webpack-dev-middleware\\package.json'
}
Go to the path specified in the internal error. You should find that the package.json file at that path is indeed missing.
Resolve that underlying "package.json" issue as you see fit. (for me, this was by deleting the C:/Root/Apps/#V/#Modules/firebase-feedback/Main/node_modules folder, then running npm install in the Main folder)
Note that in my case, the underlying issue (of the missing package.json file) appears to have been caused by me accidentally running npm install from the parent project (which uses my firebase-feedback library), while I had that library "npm linked".
I normally use npm-safe-install to avoid these sorts of issues (when using npm link), but I must have forgotten sometime recently -- leading to NPM mangling the npm-linked libraries' node_modules folders.
Similar issues relating to npm link have happened before, but I hoped NPM would have patched these sorts of issues by now. Apparently not; though version 7 of NPM has been stated as going to have a rewrite in that area, so hopefully that will solve it long term.
You have to remove project Package-lock.json file. then try to install what you want.
The error may vary on what npm internals file it can be thrown! (And i wonder for all the possible reasons)! And it should be a bug!
(in my last case: it was on [_canPlaceDep] method of the file build-ideal-tree.js of npm!
Note
If none of the common methods works! And that you are using nodejs v15+ and one of latest npm version! Go to the last part! The problem that i call the nodejs VERSIONS HELL! (NOTE: after reflection! For npm it may not be a version HELL! READ TO KNOW)
How to try to solve
Removing node_modules
\rm -r node_modules
Reinstall after
npm install
(NOTICE: that may still not work)
You can try to remove package.lock too!
Clearing the cache
npm cache clean --force
That can work if the cache get currupted somehow! But the common error is more of Unexpected end of JSON input while parsing near ...
You can check my answer here (that explain it well): https://stackoverflow.com/a/52249619/7668448
Removing package.lock (which is not adviced)
rm package.lock
Why not advised
From #DanielIM comment
No, it should not. This is "the recommended workaround" but is incredibly broken in practice. Having a locked dependency in package.json in no way ensures that dependency's dependencies will remain consistent, so removing the package-lock.json file, npm installing, and generating a newlock file *will allow those sub-dependencies to change, which often completely breaks any future building. Using an existing lock file is often the only way to maintain builds (that is the POINT of the file, after all) so removing it completely goes against the reason for its existence.
So generally it's nice to leave that as a last resort! If it does not work ! You can try with removing node_modules too!
Reinstalling nodejs or NPM
A problem can happen at npm level! Trying to reinstall can be a nice way!
To test quickly in place of reinstalling! Using NVM (nodejs version manager) and switching to another version is fast and interesting! Because we can also test for VERSION HELL PROBLEM!
If it works after switch! Then either it's a problem with npm and a reinstallation may fix it! Or it's a version Hell problem (a bug)!
How to reinstall fast! Again use nvm!
nvm uninstall v15
then
nvm install v15
then use it
nvm use v15
You can just install another version and use it! (v14 for example)
Check the VERSION HELL PROBLEM And how to use nvm to switch between versions!
The uncommon or new! THE VERSIONS HELL
In this year! I encountered many nodejs VERSIONS HELL problems! (I like to call them that) (because i gave them a name! The skies are blessing me with more) (irony)
To list them quickly:
Node v14 HELL (POSTGRES) and causing problem for pg module (postgres) [because of breaking changes! That pg was depending on!] (if you are using knex or any orm or query builder! And use it with postgres! Big chance you'll encounter it! If you just upgrade nodejs version alone! [Solution: upgrade pg versoin to the latest (>=8.0.3) [They made a fix] (Can check a full detailed explanation here https://stackoverflow.com/a/64639717/7668448)]
Typescript v4 HELL! A similar problem! Where typescript in one of my project fail internally with cannot read property "" of undefined! Rolling back to v3.9 run successfully! No problem!
Fix Our problem (Cannot read property 'matches' of undefined)
If you are using node v15! Try with node v14 (npm v6.14.8)! That may be it! An npm bug! That's a first thought can be! That what i thought at first!
That's was the case for me! In this last problem! I tried all the solutions that i'm familiar with! And they were already listed here too! None worked! And more when i removed node_modules! I was Please not another version HELL! And yea it was exactly that! It worked well with **node v14** (npm v6.14.8). Which suggest a [BUG].
Then reflecting a bit on it! It was like hey! When i change the version! I'm using another nodejs installation! Which can just not have the problem. A problem with npm structure or something and a re-installation may fix it (as mentioned above)!
After it ! I tried with node v15.3.0. And it worked all ok! After the installation was all right done! I went back to node v15.0.1! And it worked again! So the problem is absolutely not a VERSION HELL problem
I'm still uncapable to explain what did happen! But in short! Using NVM! To try with another version! Is a good way to go about it! You can reinstall quickly the current version too!
Big Take down (for the VERSION HELL)
Starting from nodejs v14! And v15! Or just generally! It's nice to be skeptical about the versions! More of a reason when it doesn't make sense! And that's about all the problems not just npm! There is so many VERSIONS HELL problems! I encountred 2 up to now! Being alerted to the VERSIONS HELL can save you a lot of time!
How to test fast and also switch nodejs version quickly
To be fast at testing this and checking! Mostly for any internal error that will come! I'll google it quickly! And try another version of nodejs or whatever in question (ex: typescript)! I can too debug (console.log) The internal file where the error was thrown! And try to figure out something!
But that's it! It's really interesting to check for other versions! (nodejs, typescript, ... [remember be skeptical or alerted])
For nodejs To do it quickly:
NVM to switch quickly nodejs versions (npm)
Use NVM (nvm is a version manager for node.js,)
Quick installation of version in NVM
nvm install v14
Quick switch to another node version
nvm use v14
(Check the doc for the details! And installation process)
For switching and testing some npm module version (ex: typescript)
If it's a cli tool! you can install a precise version globaly
npm i -g typescript#3.9
use the # syntax!
Once you verify and test you can switch back to whatever you like!
If it's in a project! You can do the same (not globally)! use the # syntax to precise the version!
npm i moduleName#<versionSpecifier>
or with saving
npm i moduleName#<versionSpecifier> --save
Version specifier use SEMVER convention (https://semver.org/).
Last tip (use npx in your scripts)
It's nice to set a version internal to the project! For example
"devDependencies": {
"#types/cors": "^2.8.6",
"#types/gulp": "^4.0.6",
"cross-env": "^6.0.3",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"nodemon": "^2.0.4",
"ts-node": "^8.10.2",
"typescript": "^3.9.7", // <===== Typescript version 3.9 (for this project)
"jest": "^26.6.3"
}
In scripts i use npx:
"scripts": {
"build": "npx tsc && gulp build",
When we use npx this way with a nodjes module cli tool! npx will check first if the module is available in the local node_modules! If found will use it (use global otherwise, or Download latest and run)!
So doing what i'm suggesting! Will make sure your project will run independently from whatever you have in global!
(Read more about npx if you don't know the tool well)
Following steps work for me -
Delete npm and npm catch folder from ../AppData/Roaming
Install latest node js for here.
Retry all the steps according to your repo.

Installing and using npm (Node.js) module on Windows 2008 server

Can someone please advise - how to resolve this? This setup works fine locally on Windows 7 laptop, but fails on Windows 2008 server.
Here is the setup:
1. Using ASP.NET Core App and NodeServices on Windows Server 2008.
2. Installed Node.js and NPM on the server.
Logged in as one of the admin accounts "xyz". When I install a npm module - in this case, cypress test framework, it installs under the path:
C:\Users\xyz\AppData\Local
But when I run the application, it looks for the module under the path:
C:\Windows\system32\config\systemprofile\AppData\Local\Cypress\Cache\3.1.5\Cypress\
The application fails, complaining that the module is not found.
Things I tried so far:
1. Copied the cypress module directly from user localappdata folder to above location. Then it works.
2. Tried giving full path to the var cypress = require('cypress') - it finds the module, but whenever we try to use cypress, gives the same error.
3. Tried changing the nom prefix as well as cache location to the above path, but npm install cypress always installs under user's localappdata path only.
Any ideas on how to - either make the npm install, install the module at desired location. OR make the application look at the desired path?
Thanks a lot.
Here is the error:
An unhandled exception occurred while processing the request.
NodeInvocationException: No version of Cypress is installed in: C:\Windows\system32\config\systemprofile\AppData\Local\Cypress\Cache\3.1.5\Cypress
Please reinstall Cypress by running: cypress install
----------
Cypress executable not found at: C:\Windows\system32\config\systemprofile\AppData\Local\Cypress\Cache\3.1.5\Cypress\Cypress.exe
----------
Platform: win32 (6.1.7601)
Cypress Version: 3.1.5
Error: No version of Cypress is installed in: C:\Windows\system32\config\systemprofile\AppData\Local\Cypress\Cache\3.1.5\Cypress
Please reinstall Cypress by running: cypress install
----------
Cypress executable not found at: C:\Windows\system32\config\systemprofile\AppData\Local\Cypress\Cache\3.1.5\Cypress\Cypress.exe
----------
Platform: win32 (6.1.7601)
Cypress Version: 3.1.5
at raise (C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\errors.js:161:13)
From previous event:
at C:\inetpub\wwwroot\EmbeddedDashboard\node_modules\cypress\lib\errors.js:169:37
at C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\tasks\verify.js:48:60
From previous event:
at checkExecutable (C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\tasks\verify.js:43:11)
at C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\tasks\verify.js:213:12
at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
at Object.start (C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\tasks\verify.js:212:6)
at Object.start (C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\exec\run.js:130:19)
at C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\cypress.js:29:19
at _fileCreated (C:\inetpub\wwwroot\projectTest\node_modules\tmp\lib\tmp.js:246:7)
at FSReqWrap.oncomplete (fs.js:82:15)
From previous event:
at Object.run (C:\inetpub\wwwroot\projectTest\node_modules\cypress\lib\cypress.js:26:28)
at module.exports.cypress.run.then (C:\inetpub\wwwroot\projectTest\Scripts\RunTests.js:4:13)
at C:\Windows\TEMP\mecqsmig.e5o:166:18
at IncomingMessage.<anonymous> (C:\Windows\TEMP\mecqsmig.e5o:186:37)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:474:9)
at process._tickCallback (node.js:388:17)
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.InvokeExportAsync<T>(NodeInvocationInfo invocationInfo, CancellationToken cancellationToken)
Cypress uses cachedir to find the correct location to install Cypress into. C:\Windows\System32\config\systemprofile is the home folder of the SYSTEM user on Windows. Somehow, npm install is being executed as SYSTEM, not as your user. This would cause Cypress will attempt to install to SYSTEM's %APPDATA% directory, which is C:\Windows\System32\config\systemprofile.
This would make sense, according to the system requirements of Cypress:
Windows 7+, only 32bit binaries are provided for Windows.
I figured out how to resolve this. For some reason, when I run the application, even though it is configured to run under a service account, it still kept using the default system location for cache location.
You can configure the cache location of Cypress by setting an environment variable to your desired location. That resolved the issue for me. Here is the link to it: https://docs.cypress.io/guides/getting-started/installing-cypress.html#Binary-cache
Basically, you set a value to this environment variable CYPRESS_CACHE_FOLDER and you are set.
Hope this helps someone.

Error: Fontconfig warning: ignoring UTF-8: not a valid region tag

I have Ubuntu 18.04.1 LTS Instance running Nginx and NodeJs project, I am trying to create a PDF using html-pdf library but Its giving me following issue.
Error: Fontconfig warning: ignoring UTF-8: not a valid region tag
at ChildProcess.emit (events.js:182:13)
at ChildProcess.EventEmitter.emit (domain.js:442:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
I have tried all the possible solution available on the internet for eg.
https://github.com/ariya/phantomjs/issues/13433
Might be I am missing some step but In the end I am still stuck at generating PDF.
Thank you In Advance
Please add these following using Octave-CLI
LANG="en_US.UTF-8"
LANGUAGE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
That resolved the issue for me.

Can't run nightmare script after switching pc

I have a script using nightmare and which works on my pc ,and couldnt get it working on another pc.
This is the error im getting :
Error: spawn D:\Projects\Lounge\Lounge\node_modules\electron-prebuilt\dist\elect ron.exe ENOENT
at exports._errnoException (util.js:874:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at doNTCallback2 (node.js:439:9)
at process._tickCallback (node.js:353:17)
at Function.Module.runMain (module.js:469:11)
at startup (node.js:134:18)
at node.js:961:3
It seems like its searching for the electron on my pc's path , how could i change it? I have the electron exec , in the node moudle , but the path is diffrent (F:\Lounge\Lounge\node_modules\electron-prebuilt\dist\electron.exe)
I have found out why it didn't work.
Nightmare has a native dependency which is installed on the user's home folder.
When i moved the project, i copied only the node_modules folder, and nightmare couldn't find the reconfigured binary path.
In order to solve this, i reinstalled nightmare using npm: npm install nightmare, or even better, i created a package.json file and stated my dependecies on it, and when i moved over the project (without node_modules), i reinstalled the dependencies using npm install.
Looks like you are running the script from D:\Projects\Lounge\Lounge. Try changing directory to F:\Lounge\Lounge and run the script.

Resources