Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

TransportNodeHID throwing error #874

Open
directcuteo opened this issue Jun 7, 2022 · 0 comments
Open

TransportNodeHID throwing error #874

directcuteo opened this issue Jun 7, 2022 · 0 comments

Comments

@directcuteo
Copy link

Hello!

Description

I have a NodeJS project where I implemented a Ledger sign functionality.
This project is created as a library and can be used standalone as a Node app, or with npm imported in an Angular Web Application.

In my file where I try to connect to the Ledger Device, I import both TransportNodeHID and TransportWebHID and I try to connect to the one that work for current context dynamically.

Code sample

  import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
  import TransportWebHID from '@ledgerhq/hw-transport-webhid';

  private async setTransport(): Promise<void> {
    if (!this.transport) {
      try {
        this.transport = await TransportNodeHid.create();
      } catch (e) {
        this.transport = undefined;
        console.error(e);
      }
    }
    if (!this.transport) {
      try {
        this.transport = await TransportWebHID.create();
      } catch (e) {
        this.transport = undefined;
        console.error(e);
      }
    }
  }

The Problem

The problem is when I import this project (as a dependency in the package.json) in my Angular App.
There is something Node specific in TransportNodeHid because I receive at application startup: 'require is not defined')

If I remove TransportNodeHid from the file everything works. What should be the way to go here so I can have this project handling both NodeJS and browser?
Thank you!

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

No branches or pull requests

1 participant