0xPolygonMiden / miden-client

Client library that facilitates interaction with the Miden rollup
MIT License
39 stars 30 forks source link

Error Running `miden-client` Library in Node.js - "fetch failed" Due to Deprecated Parameters #595

Closed iamyeasin closed 1 week ago

iamyeasin commented 2 weeks ago

Description

While attempting to run the miden-client npm library in a Node.js environment, I'm encountering an error related to deprecated parameters and fetch functionality.

Observed error

using deprecated parameters for the initialization function; pass a single object instead
node:internal/deps/undici/undici:13185
      Error.captureStackTrace(err);
            ^

TypeError: fetch failed
    at node:internal/deps/undici/undici:13185:13
    at async __wbg_init (file:///Users/yeashinrahman/Desktop/miden-poc-node/node_modules/@demox-labs/miden-sdk/dist/index.js:13155:51)
    at async Cargo (file:///Users/yeashinrahman/Desktop/miden-poc-node/node_modules/@demox-labs/miden-sdk/dist/index.js:13260:21)
    at async file:///Users/yeashinrahman/Desktop/miden-poc-node/node_modules/@demox-labs/miden-sdk/dist/index.js:13302:5 {
  [cause]: Error: not implemented... yet...
      at makeNetworkError (node:internal/deps/undici/undici:8968:35)
      at schemeFetch (node:internal/deps/undici/undici:10363:34)
      at node:internal/deps/undici/undici:10212:26
      at mainFetch (node:internal/deps/undici/undici:10231:11)
      at fetching (node:internal/deps/undici/undici:10179:7)
      at fetch (node:internal/deps/undici/undici:10048:20)
      at fetch (node:internal/deps/undici/undici:13183:10)
      at fetch (node:internal/bootstrap/web/exposed-window-or-worker:72:12)
      at __wbg_init (file:///Users/yeashinrahman/Desktop/miden-poc-node/node_modules/@demox-labs/miden-sdk/dist/index.js:13152:26)
      at Cargo (file:///Users/yeashinrahman/Desktop/miden-poc-node/node_modules/@demox-labs/miden-sdk/dist/index.js:13260:27)
}

Node.js v20.18.0

Related Nodejs Environment codes

Below is the code snippet where I'm using the miden-client library in a Node.js Express application:


import express from 'express';
import { WebClient } from "@demox-labs/miden-sdk";

const app = express();
const port = 3000;

app.get('/', async (req, res) => {
    const webClient = new WebClient({
        nodeUrl: "http://18.203.155.106:57291" // Pass the node URL in an object
    });

    try {
        await webClient.create_client(); // Initialize the client
        res.send('Hello World! Client created successfully.');
    } catch (error) {
        console.error("Error creating client:", error);
        res.status(500).send('Error creating Miden client.');
    }
});

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
});
julian-demox commented 1 week ago

The typescript sdk is designed to work only in the browser context at the moment. I'd suggest using the rust client for any server-side applications, it will be more performant as well.

iamyeasin commented 1 week ago

The typescript sdk is designed to work only in the browser context at the moment. I'd suggest using the rust client for any server-side applications, it will be more performant as well.

Yes, I was thinking the same thing.