crypto.randomBytes is not a function
See original GitHub issueExpected behavior
Should be able to import steem library into my vue,js project.
Actual behavior
Getting the following error: [Vue warn]: Error in mounted hook: “TypeError: crypto.randomBytes is not a function” on the following line: var steem = require(‘steem’)
The exception is thrown from the nodeRandom function in secure-random.js. I put a breakpoint in that function and I can see that require(‘crypto’) returns an empty object:
> crypto
<- {}
How to reproduce
I seem to be able to reproduce the problem by just invoking: require(‘steem’)
The reported error is in secure-random.js, in the function nodeRandom.
I have verified that I can invoke the crypto.randomBytes function directly from my application. The following works: console.log(require(‘crypto’).randomBytes(64)) so I’m wondering if the steem library somehow messes up crypto.
Environment information
Using node 8.10 on Ubuntu 18.04 Application uses the Quasar UI framework with vue.js.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Related StackOverflow Question
This seems to be vue-cli specific problem. If application is running or built using vue-cli
process.pidis set to1.secure-randomchecks forprocess.pidand if it is a number it assumes you are running inside of node, which causes the library not to work.https://github.com/jprichardson/secure-random/blob/master/lib/secure-random.js#L20
You can use https://github.com/jnordberg/dsteem It should be more than enough for most usecases.