S. Karki
S. Karki

Reputation: 458

TypeError: Cannot read property of 'hash' of undefined in argon2 and bcrypt

I'm using Nestjs and have tried both libraries argon2 and bcrypt.

import argon2 from 'argon2' and import bcrypt from 'bcrypt' are both causing the same error.

When I hover over hash in userDto.password = await argon2.hash(userDto.password);, I can see that the proprty exists but I keep getting the error.


Yes a lot of questions have been asked about the issue in bcrypt which in most cases was caused by importing from bcryptjs.

I tried clearing both npm and yarn cache, deleted and reinstalled node_modules multiple times.

But they don't seem to work for argon2 and bcrypt both.

Upvotes: 1

Views: 2257

Answers (1)

Try this:

import * as argon2 from "argon2";

const hash = await argon2.hash(..);

Upvotes: 3

Related Questions