speakeasyjs / speakeasy

**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
MIT License
2.68k stars 229 forks source link

Can't resolve 'crypto' #113

Closed ninofiliu closed 5 years ago

ninofiliu commented 5 years ago

Hi Angular users!

As some of you may have encoutered, the line:

import * as speakeasy from 'speakeasy';

throws the error

./node_modules/speakeasy/index.js
Module not found: Error: Can't resolve 'crypto' in 'path/to/node_modules/speakeasy'

I resolved it by commenting out, in path/to/node_modules/speakeasy:

It now works but I'm worried about the side effects. I think that if I don't use the exports I've commented out (which are, by the way, deprecated) I think that everything is going to be alright but I first wanted to check with more experienced users.

Herover commented 5 years ago

Sorry for this late answer, but for people running into this problem: crypto is a node.js library and not available in the browser. Since there seems to be no way to provide a alternative to crypto theres no way to use this library in a browser except for removing the import and not use any functions related to generating or verifying keys (which you probably shouldn't do in a browser anyways?).

ninofiliu commented 5 years ago

I was using speakeasy as a server response emulation in my front-end while waiting for the back-end team to implement the rest of the MFA, so I needed speakeasy in the front-end but not for production.

But thanks for the (late) input! This resolves my issue.