Skip to content

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

@thanapat-waterledger

Description

@thanapat-waterledger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions