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

regeneratorRuntime is not defined #332

Closed
MicahZoltu opened this issue Mar 26, 2019 · 10 comments
Closed

regeneratorRuntime is not defined #332

MicahZoltu opened this issue Mar 26, 2019 · 10 comments

Comments

@MicahZoltu
Copy link
Contributor

MicahZoltu commented Mar 26, 2019

main.js

require('@ledgerhq/hw-transport-node-hid')

Running this program results in regeneratorRuntime is not defined.

      var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(path) {
                                                 ^

ReferenceError: regeneratorRuntime is not defined
    at C:\...\node_modules\@ledgerhq\hw-transport-node-hid\lib\TransportNodeHid.js:86:50
    at C:\...\node_modules\@ledgerhq\hw-transport-node-hid\lib\TransportNodeHid.js:125:6
    at Object.<anonymous> (C:\...\node_modules\@ledgerhq\hw-transport-node-hid\lib\TransportNodeHid.js:202:2)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

#266 says I need to do require('babel-polyfill'), but that just results in Cannot find module 'babel-polyfill'.

Presumably I can install babel-polyfill as a dependency to resolve this, but now we are getting pretty deep into the weeds. This definitely feels like a bug in the hw-transport-node-hid module. Why do I need a babel polyfill to call a js library with a modern version of node (v10.15.0)? If this is a hard dependency, why do I need to depend on it rather than getting it transitively? Why are packages being published that depend on transpilers? Transpiling should be done before the package is uploaded to NPM.

Most importantly, why are all of the GitHub issues where people have brought this up closed? This issue certainly isn't fixed, and it certainly isn't proper behavior of a library.

@gre gre pinned this issue Mar 27, 2019
@gre
Copy link
Contributor

gre commented Mar 27, 2019

I suspect this is due to https://github.com/LedgerHQ/ledgerjs/blob/master/.babelrc#L10 , we'll need to assess in our side why we needed that in the past and if we can drop it.
I've not tried it but I suspect by removing that, the babel transpilation will be lighter, typically async/await, let-of loops, are available in modern langages now so we don't need to transform these (and when we transform these, that's when this polyfill is needed).

The only problem we have on our side is that our Ledger Live Desktop build still uses an old version of babel so it might become important we migrate on our side to more recent versions.

@harshjv
Copy link
Contributor

harshjv commented May 11, 2019

Workaround

If you are using firmware 1.5.5 or above with latest ledger apps, you can use this;

import LedgerProvider from '@liquality/ledger-provider'
// or const LedgerProvider = require('@liquality/ledger-provider')

const LedgerTransport = LedgerProvider.getTransport({ config: useWebBle? })

and then use LedgerTransport instead of @ledgerhq/hw-transport-node-hid / @ledgerhq/hw-transport-webusb / @ledgerhq/hw-transport-web-ble.

@liquality/ledger-provider returns proper Ledger transport for web/node.

Example: https://cross-chain-playground.hv.pizza/
Repo: https://github.com/liquality/chainabstractionlayer/tree/dev/packages/ledger-provider

Cheers.

@shrugs
Copy link

shrugs commented Jun 12, 2019

we definitely want to ship an es5 CJS module as well as an es module here so that bundlers can pull the one the understand. projects should also be in charge of making sure that all of the features that this module expects are available (either natively or polyfilled) without the apparent dependency on regenerator-runtime

@anymos
Copy link

anymos commented Jun 23, 2019

Great!, same issue here, any news regarding this ? nd no, I do not want to use the latest firmwar version that critically limit the memory on the device ...

@drewstone
Copy link

drewstone commented Jul 10, 2019

Can confirm I have the same issue with both u2f and webusb transports.

EDIT: Temporarily solved by importing babel-polyfill

@webmaster128
Copy link
Contributor

As a temporary solution for @ledgerhq/hw-transport-webusb and @ledgerhq/hw-transport-node-hid, importing regenerator-runtime seems to be sufficient. The module is much more lightweight than babel-polyfill and thus has less side-effect (like conflicts with different core-js versions in certain environments).

E.g.

import "regenerator-runtime"; // required by @ledgerhq/hw-transport-node-hid
// ...
import Transport from "@ledgerhq/hw-transport";
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";

@lacksfish
Copy link

@webmaster128 Thank you, nice work-around, can't wait for #241 getting a rebase and merge.

@GregTheGreek
Copy link

GregTheGreek commented Dec 5, 2019

Any status update on this?

@gre
Copy link
Contributor

gre commented Dec 6, 2019

yes we are migrating all our projects and once everything is stable and working we should be able to merge #428 that no longer have this issue's problem

@gre
Copy link
Contributor

gre commented Dec 17, 2019

This is fixed by v5.0.0

@gre gre closed this as completed Dec 17, 2019
@gre gre unpinned this issue Dec 17, 2019
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

9 participants