Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud Functions deployment fails after upgrading to sharp 0.33.0, _ZSt28__throw_bad_array_new_lengthv: symbol not found #3872

Closed
4 of 8 tasks
bhr opened this issue Nov 29, 2023 · 9 comments

Comments

@bhr
Copy link

bhr commented Nov 29, 2023

Possible install-time or require-time problem

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

Are you using a supported runtime?

  • I am using Node.js 18 with a version >= 18.17.0
  • I am using Node.js 20 with a version >= 20.3.0
  • I am using Node.js 21 or later

If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.

Are you using a supported package manager?

  • I am using npm >= 9.6.5
  • I am using yarn >= 3.2.0
  • I am using pnpm >= 7.1.0

If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory?

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

Description

After upgrading to sharp 0.33.0, Google Cloud Functions deployment fails with the following error:

{"severity":"ERROR","message":"Error: Could not load the \"sharp\" module using the linuxmusl-x64 
runtime\nERR_DLOPEN_FAILED: Error relocating /workspace/dist/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-
x64.node: _ZSt28__throw_bad_array_new_lengthv: symbol not found\nPossible solutions:\n- Add platform-specific 
dependencies:\n    npm install --os=linuxmusl --cpu=x64 sharp\n  or\n    npm install --force @img/sharp-linuxmusl-x64\n- Update 
your OS:\n    Found musl 1.2.2\n    Requires musl >=1.2.2\n- Consult the installation documentation: 
https://sharp.pixelplumbing.com/install\n    at entryFromArgs (/workspace/dist/node_modules/firebase-
functions/lib/logger/index.js:130:19)\n    at Object.error (/workspace/dist/node_modules/firebase-
functions/lib/logger/index.js:116:11)\n    at console.error (/workspace/dist/services/cloud-
functions/functions/lib/services/logging.js:13:32)\n    at exportFunctions (/workspace/dist/node_modules/better-firebase-
functions/lib/index.js:1:41429)\n    at Object.<anonymous> (/workspace/dist/services/cloud-
functions/functions/lib/index.js:21:49)\n    at Module._compile (node:internal/modules/cjs/loader:1105:14)\n    at 
Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)\n    at Module.load 
(node:internal/modules/cjs/loader:981:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n    at 
Module.require (node:internal/modules/cjs/loader:1005:19)"}

package.json

"dependencies": {
    "@img/sharp-linuxmusl-x64": "^0.33.0",
    "sharp": "^0.33.0",
   ...
  },
@lovell
Copy link
Owner

lovell commented Nov 29, 2023

Hello, my understanding of Google Cloud Functions is that they provide glibc-based Ubuntu Linux.

https://cloud.google.com/functions/docs/concepts/execution-environment

Error: Could not load the "sharp" module using the linuxmusl-x64 runtime

However this error message suggests you're using a musl-based operating system such as Alpine Linux.

My best guess would be that you're using a Docker image with an outdated version of libstdc++.

nodejs/node#41058 might be relevant.

@lovell
Copy link
Owner

lovell commented Dec 5, 2023

@bhr Were you able to make any progress with this?

@bhr
Copy link
Author

bhr commented Dec 5, 2023

@lovell your best guess is right, we're using a docker image to deploy the GCF. Gonna take a look at this today.

@lovell
Copy link
Owner

lovell commented Dec 5, 2023

Thanks for the update, if you need further help please provide a Dockerfile that allows someone else to reproduce.

@bhr
Copy link
Author

bhr commented Dec 11, 2023

Tried to add RUN apk upgrade as suggested in node#41058. Still the same issue

Simplified docker file:

FROM node:20-alpine AS base

RUN apk update && \
    apk upgrade

RUN apk add curl bash git g++ make libpng-dev rsync

# Install firebase-tools and deploy
RUN npm install --location=global firebase-tools
RUN firebase deploy --only functions --project ${PROJECT_ID}

@lovell
Copy link
Owner

lovell commented Dec 11, 2023

These look like commands used to deploy your function(s). To be able to reproduce, please provide a Dockerfile that describes/creates the runtime that you are deploying.

(The use of FROM x AS base here suggests you're using multi-stage Dockerfiles. If this is the case, please make sure you're copying everything that is needed between stages, which might include system dependencies, and make sure all stages are using exactly the same underlying OS version.)

@bhr
Copy link
Author

bhr commented Dec 12, 2023

Actually, our Dockerfile is not an issue. Local deployment of the Firebase Cloud Functions work. It just fails in Cloud Build, where we use the firebase community builder image. Looking at the Dockerfile source, I can see it uses node:lts-alpine3.18

@bhr
Copy link
Author

bhr commented Dec 12, 2023

For anyone who comes across this, the solution to resolve the issue is to rebuild the firebase community builder image as outlined here.

@bhr bhr closed this as completed Dec 12, 2023
@lovell
Copy link
Owner

lovell commented Dec 12, 2023

Thank you for the update, glad to hear you got it working.

@lovell lovell changed the title Google Cloud Functions deployment fails after upgrading to sharp 0.33.0 Google Cloud Functions deployment fails after upgrading to sharp 0.33.0, _ZSt28__throw_bad_array_new_lengthv: symbol not found Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants