minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
928 stars 273 forks source link

Cannot use Minio in Deno #1261

Closed riderx closed 7 months ago

riderx commented 7 months ago

IT's now allowed to use in Deno:

import { Client } from 'npm:minio'

function initR2(c: Context) {
  const accountid = '*****'
  const access_key_id = '*****'
  const access_key_secret = '*****'
  const params = {
    endPoint: `${accountid}.r2.cloudflarestorage.com`,
    region: 'us-east-1',
    useSSL: true,
    accessKey: access_key_id,
    secretKey: access_key_secret,
  }

  console.log('R2 params', params)
  const client = new Client(params)
  console.log('R2 client', client)
  return client
}
initR2()

And then i get error like that:

e Error: unreachable
    at arch (ext:deno_node/_process/process.ts:16:11)
    at get arch [as arch] (node:process:275:14)
    at new TypedClient (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/minio/7.1.3/dist/esm/internal/client.mjs:98:62)
    at new Client (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/minio/7.1.3/dist/esm/minio.mjs:44:8)
aldy505 commented 7 months ago

The SDK requires some Node.js dependencies. See here

https://github.com/minio/minio-js/blob/6b9845d3c7fa5f5013f3fa1058f85a9480dcd434/src/internal/client.ts#L1-L6

Perhaps Deno support will be available sooner or later. I don't have any idea about that.

riderx commented 7 months ago

Deno does support node deps since a year :) https://docs.deno.com/runtime/manual/node/compatibility It seems the problem is not them, maybe one of the other npm deps. Maybe fs is problematic also.

can I try to work on it ?

aldy505 commented 7 months ago

Sure go ahead. But the typescript rewrite has been going really slow right now.

riderx commented 7 months ago

I'm not sure to understand what you mean by "typescript rewrite" ?

riderx commented 7 months ago

I just realized it works in Deno with ESM magic!

Just import like that

import { Client } from "https://esm.sh/minio?target=deno"

TADA :)

riderx commented 7 months ago

For the record here is the issue i get on Deno or Cloudflare workers env: CleanShot 2024-02-12 at 22 45 24@2x I created a PR to address all of these issue here: https://github.com/minio/minio-js/pull/1265