dapr / js-sdk

Dapr SDK for Javascript
Apache License 2.0
194 stars 82 forks source link

Having trouble using the JavaScript SDK in React #546

Closed myarasi8 closed 8 months ago

myarasi8 commented 1 year ago

I am creating a react application that I need to invoke dapr using the JavaScript SDK as described here:

https://docs.dapr.io/developing-applications/sdks/js/js-client/

I am trying to invoke dapr from the client side in my App.js file like so:

import { useState } from "react";
import { DaprClient, DaprServer, HttpMethod, CommunicationProtocolEnum } from "@dapr/dapr";

const daprHost = "127.0.0.1"; // Dapr Sidecar Host
const daprPort = "3500"; // Dapr Sidecar Port of this Example Server
const serverHost = "127.0.0.1"; // App Host of this Example Server
const serverPort = "50051"; // App Port of this Example Server

// HTTP Example
const client = new DaprClient({ daprHost, daprPort }); 

When I do this however I got a lot of errors like this:


Compiled with problems:
×
ERROR in ./node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression
ERROR in ./node_modules/on-finished/index.js 207:11-33
Module not found: Error: Can't resolve 'async_hooks' in '/home/asuragen/services/asgn_carrierplus_ui/node_modules/on-finished'
ERROR in ./node_modules/raw-body/index.js 302:11-33
Module not found: Error: Can't resolve 'async_hooks' in '/home/asuragen/services/asgn_carrierplus_ui/node_modules/raw-body'
ERROR in ./node_modules/@dapr/dapr/actors/ActorId.js 15:17-34
Module not found: Error: Can't resolve 'crypto' in '/home/asuragen/services/asgn_carrierplus_ui/node_modules/@dapr/dapr/actors'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
    - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "crypto": false }

Is this because the version of webpack I'm using ( ^5.88.2) isn't compactable with the version of dapr I'm using ( ^3.1.2). Or is it because I have the dapr code in App.js (client-side)? I don't currently have anything setup for server side JavaScript. I assume since this is Dapr's client side SDK I should be able to put the code in the front-end.

Please let me know if I'm missing something.

Thank you!

shubham1172 commented 1 year ago

Hi @myarasi8, this is currently unsupported. Similar issue https://github.com/dapr/js-sdk/issues/473

dapr-bot commented 8 months ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.