crypto.randomBytes is not a function

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Sekhmetcommented, Aug 11, 2018

This seems to be vue-cli specific problem. If application is running or built using vue-cli process.pid is set to 1. secure-random checks for process.pid and 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

1reaction
Sekhmetcommented, Aug 18, 2018

You can use https://github.com/jnordberg/dsteem It should be more than enough for most usecases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js crypto.randomBytes() is not a function
I ran into this same error in the command line: Uncaught TypeError: crypto.randomBytes is not a function.
Read more >
TypeError: crypto.randomBytes is not a function #150
When activating an experiment as follows: optimizelyClient.activate('experiment', 'user123') returns null and the logger shows this error ...
Read more >
Node.js crypto.randomBytes() Method
The crypto.randomBytes() method is used to generate a cryptographically well-built artificial random data and the number of bytes to be ...
Read more >
Crypto | Node.js v19.3.0 Documentation
Cipher objects are not to be created directly using the new keyword. Example: Using Cipher objects as streams: const { scrypt, randomFill, createCipheriv,...
Read more >
Uncaught TypeError crypto.randomBytes is not a function
A Node.js repl by javacrypto.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found