8

I try to convert the form input password value using bcrypt. First I installed bcrypt (npm install bcrypt --save) after I added like this

var bcrypt = require('bcrypt');
 var hash = bcrypt.hashSync(values.newPassword, 10);

Then in the cmd display so mush errors like this

 ERROR in ./node_modules/forever-agent/index.js Module not found: Error: Can't resolve 'tls' in 

What's the cause of the error, and how can the problem be resolved?

starball
  • 20,030
  • 7
  • 43
  • 238
jayanes
  • 584
  • 6
  • 10
  • 21

2 Answers2

15

So the normal bcrypt isn't like a typical library. It's written in c++ and compiled for your machine when you npm install it. It does not work in the browser because of that (and more). However, there is a pure javascript implementation that IS browser compatible (and portable in general):

bcryptjs

npm install bcryptjs

Do read their browser implementation to guide through setup. They have a few small things needing to be done to generate the cryptographically safe random numbers.

J Livengood
  • 2,729
  • 1
  • 12
  • 26
-1

var bcrypt = require('bcryptjs');

  • 1
    please avoid code only answers, instead you want to format your code and give an explanation – Soleil May 03 '23 at 00:18
  • what makes you think they're not actually using https://www.npmjs.com/package/bcrypt? And what on earth does this add on top of the existing answer? Did you mean to suggest an edit to that answer? – starball May 03 '23 at 01:40