为请求的模块/ next js 13 / app目录/ mongoose mongodb导入跟踪

ycggw6v2  于 2023-03-07  发布在  Go
关注(0)|答案(1)|浏览(131)

我的应用程序控制台中有很多错误。如何修复?
下一个js 13.2 / app目录

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/CognitoIdentityClient.js
./node_modules/@aws-sdk/client-cognito-identity/dist-cjs/index.js
./node_modules/@aws-sdk/credential-providers/dist-cjs/fromCognitoIdentity.js
./node_modules/@aws-sdk/credential-providers/dist-cjs/index.js
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js

./node_modules/mongoose/node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in 'C:\Users\79833\WebstormProjects\partApp\node_modules\mongoose\node_modules\mongodb\lib'

Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/bson.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js

./node_modules/mongoose/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in 'C:\Users\79833\WebstormProjects\partApp\node_modules\mongoose\node_modules\mongodb\lib'

Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js

./node_modules/mongoose/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@mongodb-js/zstd' in 'C:\Users\79833\WebstormProjects\partApp\node_modules\mongoose\node_modules\mongodb\lib'

Import trace for requested module:
./node_modules/mongoose/node_modules/mongodb/lib/deps.js
./node_modules/mongoose/node_modules/mongodb/lib/index.js
./node_modules/mongoose/lib/index.js
./node_modules/mongoose/index.js
./Total/db/connect.js
./Part/ssr/Ssr.js
./app/(pages)/profile/page.js

我已经尝试更新和重新安装软件包。错误没有消失。
这些并不全是错误。还有很多其他的错误。它们也看起来

cu6pst1q

cu6pst1q1#

在nextjs中,您必须像这样导出模式,这将解决您的问题

import mongoose from "mongoose";
const Schema = mongoose.Schema;

const ProductSchema = new mongoose.Schema({
    name:{type:String, required:true, unique:true},
    image:{type:String, required:true},
},{timestamps : true})

export default mongoose.models.Product || mongoose.model("Product", ProductSchema); //like this try to export every model in you app like this and it should work

相关问题