Javascript TypeError:ConnectionConfig不是构造函数
你好,我一直收到TypeError的错误:ConnectionConfig不是第22行的构造函数,我不明白为什么。我正在使用mysql包。所以我希望有人能帮我解决这个问题,因为我不知道是什么原因造成的。谢谢Javascript TypeError:ConnectionConfig不是构造函数,javascript,node.js,typescript,Javascript,Node.js,Typescript,你好,我一直收到TypeError的错误:ConnectionConfig不是第22行的构造函数,我不明白为什么。我正在使用mysql包。所以我希望有人能帮我解决这个问题,因为我不知道是什么原因造成的。谢谢 //3rd party modules import bcrypt from "bcrypt"; import mysql from "mysql"; //Interfaces import { Sql } from "./interfac
//3rd party modules
import bcrypt from "bcrypt";
import mysql from "mysql";
//Interfaces
import { Sql } from "./interfaces/sql.interface";
import { SqlTable } from "./interfaces/table.interface";
import { User } from "./interfaces/user.interface";
//Classes
import LoginAuth from "./loginAuth";
class UserAuth {
user: string;
password: string;
sqlconnection: Sql;
table: SqlTable;
hashedPass: string;
registeredUser!: User;
constructor(
user: string,
password: string,
sqlconnection: Sql,
table: SqlTable
) {
this.user = user;
this.password = password;
this.sqlconnection = sqlconnection;
this.table = table;
this.hashedPass = "";
}
registerUser() {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(this.password, salt, (err, hash) => {
this.hashedPass = hash;
const connection = mysql.createConnection({
host: this.sqlconnection.host,
user: this.sqlconnection.user,
password: this.sqlconnection.password,
database: this.sqlconnection.database,
});
connection.connect();
this.registeredUser = {
username: this.user,
password: this.hashedPass,
};
connection.query(
`INSERT INTO ${this.table.table} SET ?`,
this.registeredUser
);
});
});
}
}
export default UserAuth;
Mysql函数是异步的,您应该将它们与wait或callbacks()一起使用哦,是的,我知道了,让我试试,看看它的fixedI是否添加了回调,但我仍然收到错误,错误在第22行。您能提供堆栈跟踪吗?您显示的代码没有构造任何内容,因此不会导致错误。