Heroku Library Dependencies via Buildpack, Phantomjs + Webfonts (but generalizable to buildpacks) - linux

After forking this Heroku buildpack (for phantomjs, but I imagine this issue applies for other custom buildpacks) :
https://github.com/stomita/heroku-buildpack-phantomjs
and updating the compile script to pull from a custom phantomjs tar.bz2 file whose bin/phantomjs binary is replaced with this one:
http://arunoda.me/blog/phantomjs-webfonts-build.html
The Heroku build process works correctly, extracts the correct modified binary, but upon getting it to rasterize a web page, comes up with error message (via heroku logs, sans timestamps for succinctness):
app[web.1]: phantomjs: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by phantomjs)
app[web.1]: phantomjs: /lib/libc.so.6: version `GLIBC_2.15' not found (required by phantomjs)
app[web.1]: phantomjs: /lib/libc.so.6: version `GLIBC_2.14' not found (required by phantomjs)
I've tried simply including these files within the tar.bz2 file in various configurations (in different /lib or /usr/lib locations) but this hasn't worked. I realize there's a possibility of having to add some additional path information to the compile script in the buildpack, but perhaps because I'm not quite an Ops person I don't quite get it. Add in the research on buildpacks and people referring to the base /app directory and the compile script having a vendor one, I'm even more confused.
I think this is possible to solve: in fact, it appears that Deepsy has solved the problem here by stating "then I copied libstdc++.so.6 from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 and added it to my custom buildpack and now its working flawlessly :)"
The problem for me, like the bulk of this post is pointing to, is that I don't know what that one line entails, and would greatly appreciate any help. I've spent way too many hours on this, and am genuinely stuck.
Thanks in advance.
Update 1:
I found Deepsy's code in his github repo here and tried to do the same curl approach, also updating the LD_LIBRARY_PATH variable and chmod 777ing the folder's contents (which includes both the binaries and library files). This didn't work (the same error messages come up). Also, my binary requires libc.so.6, which his didn't, but I got that file from my OS.
Interesting too: when trying to add and mv the libc.so.6 library file into the LD_LIBRARY_PATH, my Heroku app crashes. I suspect this might be that adding that library to the LD_LIBRARY_PATH might confuse other binaries within Heroku and use my version, which for whatever reason isn't working for the Heroku instance.
Update 2:
I also tried building the phantomjs binary from scratch and was successful. Turns out I get the exact same sized binary from the second link from the top, and the same calls for the necesarry libraries (thus same errors).
Current thesis:
It might be that the phantomjs binary is seeing the correct lib files given Update 1, but the provided Heroku ones aren't up to date enough for the binary to run correctly. Or it could still be missing the library files.
Either way, I guess I'd need to somehow get phantomjs to use the library files I've provided, and I'm not sure how I'd get to do that.

Related

dyld: Symbol not found: _napi_module_register

Had my node working with the VS Code debugger last night no problem. I haven't touched anything besides install the npm mysql package.
I come back tonight and its throwing this error:
Debugger listening on [::]:49952
dyld: lazy symbol binding failed: Symbol not found: _napi_module_register
Referenced from: /Users/adamsawyers/node_modules/bufferutil/prebuilds/darwin-
x64/node-napi.node
Expected in: flat namespace
dyld: Symbol not found: _napi_module_register
Referenced from: /Users/myusername/node_modules/bufferutil/prebuilds/darwin-
x64/node-napi.node
Expected in: flat namespace
Apparently my installation of n (a node version handling package in npm) is busted somehow. My research told me that napi_module_register is part of the n package, but I'm not sure how this got messed up especially since I had it working last night.
I tried reinstalling my node packages, reinstalling n, rebuilding the project file structure, even restarting my computer. Nothing has worked so far.
Any suggestions?
Apparently VS code doesn't like v6.10.3 of nodejs which I am running to create lambda functions in AWS (that is the version specified by AWS)
I use the N package to manage my node version. After switching to the latest version 10.7.0 as of 07/25/2018 (command: sudo n latest) and rerunning the debugger in VS code, it worked perfectly
I'm still unsure as the the cause, but hopefully others find this solution helpful
This exact error happened to me because:
I needed socket.io to run on Node
Which in turn needs ws (websockets on Node)
Also, I needed to run this on an outdated Node version (Node 7) for a very good reason (believe me, I would not want to do this if I wouldn't have to)
However, trying to use it on that old version causes above error message.
Solution
This is a terrible solution, but at least I got it to work.
After some researching, I found no good solution to this. However, a close look at the source code shows that there is a fallback.js next to index.js which implements the same functionality as the native build but without needing a build. This will probably slow things down significantly, but at least it works:
yarn add module-alias
prefix your actual code with this (e.g. via node -r fallbacks.js):
// fallbacks.js
const moduleAlias = require('module-alias');
const dependencyRoot = getDependencyRoot(); // whatever is your root folder, maybe __dirname + '..'
moduleAlias.addAlias('bufferutil', dependencyRoot + '/node_modules/bufferutil/fallback.js');
moduleAlias.addAlias('utf-8-validate', dependencyRoot + '/node_modules/utf-8-validate/fallback.js');
// run actual code here...
PS: In my case, in order to allow ws to run on Node 7, I also had to babel it, since its using modern synytax.

Exception could not locate binding file after updating electron version

I'm working on updating my project from using electron version 1.2.5
to the newest electron at this time which is 1.7.7 (atleast it was when I downloaded it). My node version 6.9.1.
I've encountered a problem when I start my project with this new electron version,
the error in general is about "could not locate the binding files. and it mostly regards the async module.
There is also some part of the exception regarding node-etcd module which I use in my project (version 5.0.3)
I found some information about this type of exception online but most of them says stuffs about rebuilding some node module using some npm commands which I didn't quiet understand. I tried to install async module again in a new folder and replace it (with its deps) in the node modules folder im currently using for my project, but I still got the same error.
I'm working in an offline enviorment where I can't take my project "out" to a computer with internet access, I can only bring things from the web to my project (like installing in some folder and then copying that into my project) so any npm or other commands that require web connection are not available to me directly on my work computer. (I can only use them in a different computer and copy the results to a flash drive and bring them to th
Here's 2 pictures of the error (sorry about the quality, its the best I could get):
First part of error
Second part of error
The solution that fixed the problem in my case was going into node_modules - > deasync - > index.js
Before line 31 I added a newline (next to the binding line)
and wrote:
modPath = __dirname;
This solution is hacky, it was accually ly found by an associate a while back, so I am not sure why it works, it might be an issue in deasync, but it fixed the problem.

Node.js module "fibers" not taking the correct version

I'm pretty new to node.js and its package management system and its require. I'm having trouble with the following runtime error I'm getting after having installed a bunch of packages with npm install:
ERROR: Couldn't initialise framework "wdio-mocha-framework".
Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found
(required by <path>.../node_modules/fibers/bin/linux-ia32-v8-5.0/fibers.node)
at Error (native)
My understanding of the error is that the binary fibers.node was compiled with a newer libstdc++ than the one available at runtime.
It appears to me like the npm install did compile a fibers.node:
> fibers#1.0.13 install <path>.../node_modules/fibers
> node build.js || nodejs build.js
make[1]: Entering directory `<path>.../node_modules/fibers/build'
<snip some output, including warnings, here that I don't deem relevant>
Installed in `<path>.../node_modules/fibers/bin/linux-ia32-v8-3.14/fibers.node`
However, I see that the fibers.node that is throwing the error at runtime is not the same one as was compiled, and I assume that's the source of the problem.
Compiled:
.../linux-ia32-v8-3.14/fibers.node
Used at runtime and fails:
.../linux-ia32-v8-5.0/fibers.node
So I'm guessing and hoping that if I could convince wdio-mocha-framework to use the locally-compiled fibers.node, it would work. My questions are thus:
Would that fix it?
If so, how do I achieve that?
If not, what's the correct direction to take to further understand and fix this error? Perhaps instead of getting 3.14 to be used at runtime, I should be convincing 5.0 to be compiled at install-time? Or ... other?
Your help is most sincerely appreciated.
Update/Edit:
I think I solved this on my own, in case anyone ever finds this poor, dusty old question lying forgotten on the back of a shelf somewhere...
The problem was apparently due to multiple versions of node/node-gyp that were installed in my environment in parallel, and the build process, even though it was started with a newer version of node, was finding node-gyp in the $PATH and that's apparently what caused the old version of fibers to be built. At least, I think so.
Just had this problem recently. I managed to solve it just by uninstalling the current version of Node.JS (I had the most recent, in this case 9.5.0) and installing the recommended, in this case 8.9.4. and the issue is gone. hope this helps someone.

Error after packaging the app with electron-packager

I'm new to Electron, and I really love it so far, but I'm unable to package any of mine apps, at first I thought that it's maybe something related to my code, then I download "https://github.com/atom/electron-quick-start" run npm install and then I run "electron-packager . FooBar --platform=darwin --arch=x64 --version=0.28.2" it build the app but when I try to open it I get
so I didn't touch any code from the example, just wanted to build it and I got an error, what am I doing wrong? Thanks!
The versions of electron are moving very very fast.
And some times, they don't respect the "old" ways to do things (for example, declaring the app).
I advise you to not use the 0.28.2 version of electron but the most recent one.
It is very likely that the version of electron-prebuilt you are using to develop is much much much more recent than the 0.28.2 version. So, you are developing with something much newer, and then you are building with 0.28.2. This would cause the exact error that you are seeing, as older versions may not have had the electron module, which your code explicitly is importing. So... that is my suggestion. Change the version in your electron-packager command from 0.28.2 to something like 0.36.0. See if that works. Or better yet, use the same version as electron-prebuilt in your package.json.
This could be a combination of factors.
First, as others stated, the version of electron that you have might be newer than the one referenced in your build command. Locate the 'electron_prebuilt' folder inside your 'node_modules' folder, and examine the package.json file and make sure the version # is the same as what you are declaring in your build command.
If they are the same, then the issue might be that you have another version of electron on your computer that node is trying to use. If you installed electron via the -g option (global), check your home folder to see if there is another different version of electron. If you find one, either delete it or rename the 'electron_prebuilt' folder you find to something else. Try your build command again, and it should work now that you've eliminated the other versions of electron_prebuilt on your computer that node was referencing.
What worked for me was to move the "electron" module from "dev-dependencies" to "dependencies" in package.json. Try this and see if it works.

Seriously debugging node.js 'Cannot find module xyz/abcd'

I have the Error: Cannot find module xyz/abcd error.
YES, the required module is installed.
According to the pseudo-code of module.require here, it should work.
I tried to dive inside require() to understand why it can't find my file. My node debugger won't step into require(). I've tried the strace / grep NOENT technique whithout success either.
Any idea how to troubleshoot a nasty require() failure ?
Note : just in case : the error comes from a file node_modules/xyz/a requiring xyz/b. It should work according to the doc.
By investigating more, I think I found a good technique :
export NODE_DEBUG=module
node my_script.js
gives such interesting traces :
looking for "/(...)/tests_init.js" in ["/home/(me)/.nave/installed/0.10.24/lib/node","/home/(me)/.node_modules","/home/(me)/.node_libraries","/home/(me)/.nave/installed/0.10.24/lib/node"]
And BTW, it shows that node is not searching at all where I thought it was. Time to investigate...
[edit] end of the story :
1) it appears that node is not treating well modules installed with npm link. require(...) sometimes fails to select files from inside a npm-linked module. I have no desire to investigate further the exact error conditions, I'll just conclude that npm link is very brittle.
2) beware of node looking for node_modules all the way into the parent dirs of current working directory ! I found that modules from parent folders of my app where sometime selected !

Resources