next.js 模块未找到:无法解析“pg-hstore "

nhhxz33t  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(103)

我使用Nextjs 13来创建一个全栈应用程序,并使用Sequelize来处理MySQL数据库。我有api文件夹来处理我的管理表单。在src/pages/api/test.js
当我调用我的模型时,它正确地工作,没有错误,我所有的表都已经创建了:
src/pages/api/test.js代码:

import { Contact } from "../../../models/models";

export default async function handler(req, res) {
  const contact = await Contact.findByPk(1);
  return res.status(200).json({ message: "Hello World!", contact });
}

字符串
但是当我在src/app/(admin)/admin/contact/page.js中使用联系人模型时,我得到了一个错误Module not found: Can't resolve 'pg-hstore'
错误屏幕截图:


的数据
src/app/(admin)/admin/contact/page.js代码:

import { AdminCard } from "../../../../../components/admin/UI/admin-components";
import AdminContactForm from "../../../../../components/admin/pages/contact-form";

import { Contact } from "../../../../../models/models";

async function AdminContact(props) {
  // const data = await Contact.findByPk(1);

  return (
    <AdminCard title="Contact">
      {/* <AdminContactForm data={data} /> */}
    </AdminCard>
  );
}

export default AdminContact;


型号contact.js编码:

import Sequelize from "sequelize";
import sequelize from "./database";

const Contact = sequelize.define("contact", {
  id: {
    type: Sequelize.INTEGER,
    allowNull: false,
    autoIncrement: true,
    primaryKey: true,
  },
  email: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  address: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  phone: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  instagram: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  facebook: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  linkedin: {
    type: Sequelize.STRING,
    allowNull: true,
  },
  whatsapp: {
    type: Sequelize.STRING,
    allowNull: true,
  },
});

sequelize
  .sync()
  .then((result) => {
    // console.log("result1 => ", result);
  })
  .catch((err) => {});

export default Contact;


我用的是Mysql,不是Postgres。

gg58donl

gg58donl1#

这是通过运行npm install pg-hstore来解决的。

相关问题