dapr / js-sdk

Dapr SDK for Javascript
Apache License 2.0
192 stars 80 forks source link

Next.js DaprServer Module not found: Can't resolve 'crypto' #584

Closed majian159 closed 4 weeks ago

majian159 commented 5 months ago

Expected Behavior

Actual Behavior

I'm attempting to start the DaprServer in instrumentation.ts in a Next.js project, but it's throwing an exception:

○ Compiling /instrumentation ...
 ⨯ ./node_modules/.pnpm/@dapr+dapr@3.3.1/node_modules/@dapr/dapr/actors/ActorId.js:15:0
Module not found: Can't resolve 'crypto'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/@dapr+dapr@3.3.1/node_modules/@dapr/dapr/index.js
./src/instrumentation.ts

The code is as follows:

import { CommunicationProtocolEnum, DaprServer } from "@dapr/dapr";

export async function register() {
  const server = new DaprServer({
    serverPort: "4000",
    communicationProtocol: CommunicationProtocolEnum.GRPC,
  });

  await server.start();
}

Steps to Reproduce the Problem

shubham1172 commented 5 months ago

image

Does this help?

https://nextjs.org/docs/messages/module-not-found#the-module-youre-trying-to-import-uses-nodejs-specific-modules

majian159 commented 4 months ago

This is not helpful; I am using the instrumentation.ts method with Next.js 14 to start the Dapr server.

This is a minimal repo: https://github.com/majian159/dapr-server-example

shubham1172 commented 4 months ago

Thanks for sharing this @majian159, I am out this week but I/someone will check this soon.

i5shuyi commented 3 months ago

@shubham1172 My latest pull request replaces the crypto module with crypto. This change will benefit all runtimes compliant with the WinterCG specification (including Next.js Edge Runtime).

dapr-bot commented 1 month 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.

dapr-bot commented 4 weeks ago

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.