Netlify function fails with "/lib64/libm.so.6: version GLIBC_2.29 not found"

Hi, I’m having an error with a netlify function that I’ve never seen before. From what I understand, a library I use has a binary that depends on /lib64/libm.so.6: version GLIBC_2.29 which is probably not present in the function’s runtime. Unfortunately this worked perfectly on my computer using netlify dev, and now I’m stuck with a function that doesn’t work and have no idea how to solve this. Can anyone help?

Function:
https://nakshatra-calc-site-j14tbsjk.netlify.app/.netlify/functions/calculate-nakshatra

Error:
Oct 25, 12:14:53 AM: edeb7158 2022-10-24T23:14:54.251Z undefined ERROR Uncaught Exception {"errorType":"Error","errorMessage":"/lib64/libm.so.6: version GLIBC_2.29' not found (required by /var/task/node_modules/swisseph/build/Release/swisseph.node)","code":"ERR_DLOPEN_FAILED","stack":["Error: /lib64/libm.so.6: version GLIBC_2.29' not found (required by /var/task/node_modules/swisseph/build/Release/swisseph.node)"," at Object.Module._extensions..node (node:internal/modules/cjs/loader:1189:18)"," at Module.load (node:internal/modules/cjs/loader:981:32)"," at Function.Module._load (node:internal/modules/cjs/loader:822:12)"," at Module.require (node:internal/modules/cjs/loader:1005:19)"," at require (node:internal/modules/cjs/helpers:102:18)"," at Object.<anonymous> (/var/task/node_modules/swisseph/lib/swisseph.js:1:16)"," at Module._compile (node:internal/modules/cjs/loader:1105:14)"," at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)"," at Module.load (node:internal/modules/cjs/loader:981:32)"," at Function.Module._load (node:internal/modules/cjs/loader:822:12)"]}

Hey @fvieira, I’m wondering if you can tell us how you’re getting that binary when you build locally? Do you get it through npm or are you downloading it directly from the vendor?

Hi @amelia, it’s through npm, it’s part of the swisseph package.

No it isn’t. It isn’t part of the npm package at all, nor is it part of any dependency of that package.

At least not that I can find. Can you point to where it is included?

Are you talking about the swisseph.node file? Sure, it isn’t part of the package source, but it gets built by that package when I run yarn, it’s nothing I’ve added separately.

I’m still researching this, and I’m probably wrong as I’m quite out of my depth here, but what I think may be happening is that the node_modules packages (specifically the swisseph) are being build in an environment with a more recent glibc version (2.29) than the one used in the Netlify functions (which from what I understand run on AWS on an Amazon Linux 2 OS which includes glibc 2.26). This is why the binary then fails to run since it expects the glibc version 2.29 but only finds the 2.26.
There’s one problem with this theory which is that the builds were supposed to be running on Ubuntu 20.04 which includes glibc 2.31, so I have no idea where the 2.29 is coming from…

Also, the binary seems to be build using node gyp, and there’s no lack of people running in similar problems in their Github’s issues (e.g. Change target GLIBC version · Issue #2317 · nodejs/node-gyp · GitHub), but I’ve yet to understand exactly what I need to do to fix this problem, I need to read and learn more.
One option may be to build the binary in an environment using glibc 2.26 and then replacing it in the node_modules during the build process, but it’s a gamble whether this will actually work…

We had seen this issue with Gatsby on Netlify and had fixed it back then:

Not sure if these apply to you, but maybe they help?

@hrishikesh Thank you very much for the help, but honestly, I can’t say if those would help or not without looking a lot deeper than I have time for, and I’ve already managed to work around the problem.
My “solution” was as follows:

  • Run an amazonlinux instance on docker
  • Use yarn to install the offending package swisseph inside the container
  • Zip the swisseph folder inside node_modules and extract it from the container
  • Use netlify build on my project to get the functions built inside .netlify/functions
  • Unzip my problematic function’s zip and replace the swisseph folder inside it’s node_modules with the one I built inside the container
  • Re-zip the function and put it in my functions folder so it’s used directly (instead of letting Netlify bundle my function with a node_modules with a non-working swisseph folder)

This made it so that the function’s zip that ends up in AWS lambda has the swisseph package built in the same environment it runs, and no longer complains about GLIBC, problem solved!
Of course, updating the code in the function is no longer very practical, but this function probably will never change so works for me!

Hey there, @fvieira

Thanks for coming back and sharing this workaround! This will definitely help future forums members who encounter something similar!