esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

Failed to import - https://esm.sh/@google-cloud/[email protected]

Open ynwd opened this issue 2 years ago • 1 comments

This package is working perfectly with npm:specifiers.

But not supported in deno-deploy.

npm: specifiers are not yet supported on Deno Deploy

So i try to use esm.

But i got this error

Error message

TypeError: Zr.default is not a constructor
    at pe.makeRequestStream (https://esm.sh/v132/@google-cloud/[email protected]/denonext/storage.mjs:35:24176)
    at pe.startUploading (https://esm.sh/v132/@google-cloud/[email protected]/denonext/storage.mjs:35:22134)
    at https://esm.sh/v132/@google-cloud/[email protected]/denonext/storage.mjs:35:17041
    at https://esm.sh/v132/@google-cloud/[email protected]/denonext/storage.mjs:35:18528
    at eventLoopTick (ext:core/01_core.js:183:11)

Failing module

export { Storage } from "https://esm.sh/@google-cloud/storage?target=denonext";
import { Storage } from "../deps.ts";

function fileToUint8Array(file: File): Promise<Uint8Array> {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();

    reader.onload = (event: any) => {
      const result = event.target.result;
      const uint8Array = new Uint8Array(result);
      resolve(uint8Array);
    };

    reader.onerror = (_event) => {
      reject(new Error("Failed to read the file."));
    };

    reader.readAsArrayBuffer(file);
  });
}

export async function uploadFile(
  f: File,
  bucket: string,
  fileName: string,
  keyFilename: string,
) {
  const storage = new Storage({
    keyFilename,
  });

  try {
    const myBucket = storage.bucket(bucket);
    const file = myBucket.file(fileName);
    const contents = await fileToUint8Array(f) as any;
    await file.save(contents);
    return `https://storage.cloud.google.com/${bucket}/${fileName}`;
  } catch (error) {
    console.error(error);
    throw new Error("Upload image failed");
  }
}

ynwd avatar Sep 05 '23 09:09 ynwd

thanks for reporting, i will check ASAP!

ije avatar Sep 05 '23 12:09 ije