As far as I can remember, each time I have used the npm module bcrypt I have run into installation/running errors. Typically these are variations of the following:
The accepted 'solution' seems to be that, should you run into these issues, you need to use up/downgraded versions of Node.js and/or of bcrypt or some combination of both. In the past, I have resolved this by downgrading bcrypt to v1.0.3, however, considering the version is now up to 3.0.3, I don't feel this is a 'solution' since it requires running older version of Node.js. If that does not solve the problem, one may need to rebuild bcrypt accordingly, by running: npm rebuild bcrypt --build-from-source
. This however, in my case, also leads to further errors with the node-pre-gyp, which, when you go down the rabbit hole, eventually leads you to having to install all kinds of other dependencies including X Code Command Line Tools!?
Regardless, this is all a bit much for me. The dependency chain is too deep and fickle/fragile in my experience. As a result, I looked around and found that there is a Javascript-based version of bcrypt called bcryptjs. It mimics the API of bcrypt, as such, you can keep your bcrypt code the same if you import the module as follows:
import * as bcrypt from 'bcryptjs';
While, it should be noted that bcryptjs is 30% slower than bcrypt. 30% sounds like a lot, but I did not notice any meaningful slowness, if anything, it was faster because bcryptjs actually worked! That being considered, I would rather have a smoother development experience with slightly slower processing, than a completely confusing and befuddling developer experience.
Through this process, I have also come to realise that Node.js has its own crypto module which I will need to explore in future.