I tried to use bcrypt to hash a password in my project, but every time the password is saved in the MongoDB without being hashed. I’ve attempted various solutions, but none have worked. In an effort to diagnose the issue, I isolated the bcrypt function and tested it separately. However, I encountered an error of “relative references” … bcrypt doesn’t require a relative reference in the import statement to function properly. I’m unsure why I’m encountering this error.
the error : “Uncaught TypeError: Failed to resolve module specifier “bcrypt”. Relative references must start with either “/”, “./”, or “../”.”
`import bcrypt from "bcrypt";
const testPassword = "test123";
const saltRounds = 10;
bcrypt.hash(testPassword, saltRounds, (err, hash) => {
if (err) {
console.error("Error hashing password:", err);
} else {
console.log("Hashed password:", hash);
}
});`