我试图设置一个MongoDB连接,但在启动我的机器人时遇到了错误。Failed to resolve module 'C:\Users\luci\Desktop\Lunar Bot\modules\data\MongoDB.js': ExpectedValidationError > s.instance(V)
该bot正在使用TypeScript开发,并在加载时转换为JS。
import mongoose from "mongoose";
export class MongoConnection {
public versions = "^7";
public mongoose!: typeof mongoose;
async onstart() {
this.mongoose = await mongoose.connect(process.env.MONGODB!);
if (this.mongoose) console.log("Connected to MongoDB Database");
return true;
}
}
export default new MongoConnection();
转换后的JS代码:
import mongoose from "mongoose";
export class MongoConnection {
constructor() {
this.versions = "^7";
}
async onstart() {
this.mongoose = await mongoose.connect(process.env.MONGODB);
if (this.mongoose)
console.log("Connected to MongoDB Database");
return true;
}
}
export default new MongoConnection();
//# sourceMappingURL=MongoDB.js.map
你知道为什么我会出错吗?
1条答案
按热度按时间lymnna711#
我想明白了
问题是
async onstart()
。它应该是async onStart()
。我打字有点太快了,没有把S大写。