Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find module "crypto" with Next.js 14 and Node 20.10.0 #201

Open
thanapat-waterledger opened this issue Mar 22, 2024 · 3 comments

Comments

@thanapat-waterledger
Copy link

When attempting to initialize hashconnect in a Next.js 14 (Typescript) application, my application fails to compile, returning the error Cannot find module "crypto". This issue occurs during both npm run dev and npm run build.

To Reproduce:
Steps to reproduce the behavior:

Setup a Next.js 14 project.
Implement the hashconnect initialization as follows:

async function initWalletConnect() {
    const connection = new HashConnect(LedgerId.TESTNET, walletConnectProjectId, appMetadata, true);

    connection.pairingEvent.on((newPairing) => {
        setWalletData(newPairing);
    });

    connection.connectionStatusChangeEvent.on((state) => {
        setConnectionState(state);
    });

    connection.disconnectionEvent.on((data) => {
        setWalletData(null);
    });

    await connection.init();

    setHashConnect(connection);
}

Run the application.
Expected behavior:
The application compiles without errors, and hashconnect initializes correctly, allowing for wallet connection functionalities.

Environment:

OS: macos 14.0
Browser: Chrome
Version of Next.js: 14.1.4
Version of Node.js: 20.10.0
Version of hashconnect: 3.0.13

@kevincompton
Copy link

Same problem here

@HakkaOfDev
Copy link

Same here :3

image

@woodevin
Copy link

This issue is due to the transitive dependency version of the hedera-wallet-connect library. This problem, documented in #190, was resolved in version 1.3.2 of HWC and addressed in this PR. However, hashconnect version 3.0.13 uses version 1.0.6 of HWC, which still contains the issue.

To resolve the issue, I overrode the dependency version in my package.json.

{
  ...
  "dependencies": {
    "hashconnect": "^3.0.13",
    "next": "14.2.5",
  },
  "overrides": {
    "hashconnect": {
      "@hashgraph/hedera-wallet-connect": "^1.3.2"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants