尝试在 backeng 中比较密码时出错 - NODE.JS

ERROR while trying to compare passwords in backeng - NODE.JS

我正在尝试比较登录验证的密码,但未成功。

我正在使用安装在服务器文件夹中的 bcryptjs.. 我不断收到此错误:

Parser.js:437
      throw err; // Rethrow non-MySQL errors
      ^

TypeError: bcrypt.compare is not a function

bcryptSync 和 genSalt 的相同错误..(试图确定...) bcrypt.hashSync 正在工作。

有什么想法吗???

这是我的代码(我排除了一些不相关的部分):

const express = require("express");
const mysql = require("mysql");
const cors = require("cors");

const bcrypt = ('bcryptjs');

const app = express();

app.use(cors());
app.use(express.json());

// Create connection

const db = mysql.createConnection({
  user: "root",
  host: "localhost",
  password: "1234",
  database: "dashboardDB",
});

// Connect
db.connect((err) => {
  if (err) {
    console.log(err + " Connection error");
  } else {
    console.log("MySql Connected...");
  }
});

app.post("/login", (req, response) => {
  const email = req.body.email;
  const password = req.body.password;

  if (email && password) {
    db.query(
      "SELECT * FROM users WHERE email = ? LIMIT 1",
      [email],
      (err, result) => {
        console.log(result);
        if (err) {
          console.log(err);
        } else if (result.length > 0) {

          bcrypt.compare(password, hash, (err, res) => {
            console.log(err, res);
        });
        

就像@Joe 写的那样:

const bcrypt = ('bcryptjs');应该是 const bcrypt = require('bcryptjs');