最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Node js应用程序中猫鼬模式的导入无法正常工作

运维笔记admin16浏览0评论

Node js应用程序中猫鼬模式的导入无法正常工作

Node js应用程序中猫鼬模式的导入无法正常工作

[每次尝试在基本锻炼应用程序中导入时都会收到错误消息

Exercise-Tracker-MERN\backend\models\exercise.model.js:1
(function (exports, require, module, __filename, __dirname) { import Schema from "mongoose";
import Schema from "mongoose";
const mongoose = require("mongoose");

const exercise = new Schema(
  {
    username: { type: String, required: true },
    description: { type: String, required: true },
    duration: { type: Number, required: true },
    date: { type: Date, required: true }
  },
  {
    timestamps: true
  }
);

const Exercise = mongoose.model("Exercise", userSchema);
module.exports = Exercise;

我正在学习教程:

回答如下:

我可以在您的代码中看到多个错误。如果您使用的是不支持es6的nodejs,则不能使用import语句,而可以使用require。另外,您正在使用未定义的userSchema创建Exercise模型。

请尝试这个

const mongoose = require("mongoose");

const exercise = new mongoose.Schema(
  {
    username: { type: String, required: true },
    description: { type: String, required: true },
    duration: { type: Number, required: true },
    date: { type: Date, required: true }
  },
  {
    timestamps: true
  }
);

const Exercise = mongoose.model("Exercise", exercise);
module.exports = Exercise;
发布评论

评论列表(0)

  1. 暂无评论