我有一个错误:
错误:与序列化包连接的“exports”未定义包子路径“./types”。
(错误:D:\Projects\pets\realtime-chat\backend\node_modules\sequelize\package.json中的“exports”未定义包子路径“./types”)。
尝试通过将所有npm和node版本更新到最新版本来解决这个问题,但是没有成功。我已经为我的应用程序设置了socket.io
服务器,并使用typescript创建了User
模型。
当我尝试用User.create({\attributes\})
创建一个新的User
时,它会抛出上面提到的Error。
server.ts
import express from "express"
import { createServer } from "http"
import { Server } from "socket.io";
import apiRouter from "./routes/api.route";
import { seq } from "./models/db"
const app = express();
app.use("/api", apiRouter);
const httpServer = createServer(app);
const io = new Server(httpServer);
io.on("connection", (socket) => {
console.log(socket.id);
});
httpServer.listen(process.env.PORT || 5000, () => {
console.log(seq.config);
seq.authenticate();
console.log("Server is started")
});
字符串
User.model.ts
import { DataTypes, Model, Optional } from "sequelize/types";
import { seq } from "./db";
interface UserAttributes {
username: string,
password: string,
email: string
}
type UserCreationAttributes = Optional<UserAttributes, "email">;
class User extends Model<UserAttributes, UserCreationAttributes> {
declare username: string;
declare password: string;
declare email: string
}
User.init({
username: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING
},
email: {
type: DataTypes.STRING
}
},
{
sequelize: seq,
tableName: "users"
});
export default User;
型
我的API.route.ts
import express from "express"
import User from "../models/User";
const router = express.Router();
router.get("/users", async () => {
await User.create({
password: "name",
username: "name"
})
});
export default router;
型
1条答案
按热度按时间zxlwwiss1#
只需直接从
sequelize
导入所有这些类型:字符串