lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
28.41k stars 1.28k forks source link

Firebase cloud function: VipsOperation: class dzsave not found #3715

Closed diego9497 closed 1 year ago

diego9497 commented 1 year ago

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

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.

What are the steps to reproduce?

I just try to call .tile() and it fails, the same cloud function works fine in the emulators (I have libvips installed globally on my computer), but is failing with the deployed cloud function.

Other functions like .toFormat are working fine in the deployed cloud functions and were successfully uploaded to the bucket.

What is the expected behaviour?

Generate the zip file.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

` generateDZI = (req: functions.https.Request, resp: functions.Response) => { const form = new formidable.IncomingForm();

return new Promise((resolve, reject) => {
  form.parse(req, async function (err: any, fields: any, files: { file: any; }) {
    const file = files.file;

    if (!file) {
      reject(`no file to upload, please choose a file. ${JSON.stringify(files)}`);
      return;
    }

    const filePath = file.path;

    const fileDir = path.dirname(filePath);
    const DZIFilePath = path.normalize(path.format({ dir: fileDir, name: "test-dzi", ext: ".zip" }));

    const bucket = admin.storage().bucket();

      return sharp(filePath)
        .tile({
          size: DEFAULT_TILE_SIZE,
        })
        .toFile(DZIFilePath)
        .then(() => {
          // Uploading the zip file.
          return bucket.upload(DZIFilePath, { destination: "new-zone-map/12345/test-dzi.zip" });
        })
        .then((response: any) => {
          console.log("DZI image uploaded");
          fs.unlinkSync(DZIFilePath);
          fs.unlinkSync(filePath);

          resolve({ response });
          return;
        })
        .catch((err: any) => {
          reject("Failed to upload: " + JSON.stringify(err, replaceErrors));
        });
  });
})
  .then((response) => {
    resp.status(200).json({ response });
    return;
  })
  .catch((err) => {
    resp.status(500).json({ error: err });
    return;
  });

}`

Please provide sample image(s) that help explain this problem

image
lovell commented 1 year ago

Please see https://github.com/lovell/sharp/issues/3581