Я рассмотрел эту проблему и нашел несколько ответов, но ни одно из решений не решило мою проблему.
Ниже приведен файл модели кода
// account.ts
const mongoose = require('mongoose');
var autoincrement = require('simple-mongoose-autoincrement');
const Accounts = mongoose.Schema(
{
id: { type: mongoose.Schema.Types.ObjectId, required: true, unique: true },
accountDetails: { type: String },
// other collection properties goes here.
}
);
Accounts.plugin(autoincrement, { field: 'id' });
module.exports = mongoose.model('Accounts', Accounts);
Ниже приведен код моего хранилища
// AccountsRepository.ts
// import { Accounts } from "../../models/accounts";
// import Accounts from "../../models/accounts";
Я пробовал два вышеупомянутых метода: импорт, но я получаю исключение, как показано ниже
File 'myPath/accounts.ts' is not a module.ts(2306)
Я сталкиваюсь с той же проблемой в других моих файлах.
// AccountsRouter.ts
import express from "express";
import accountsController from "../../controller/accountscontroller";
const accountsRouter = express.Router();
accountsRouter.get("/details", accountsController.getDetails);
exports = accountsRouter;
// App.ts
`import accountsRouter from "./accounts/accountsrouter";` --> this gives the error as below
Module 'myPath/accouts/accountsrouter"' has no default export.ts
Я не хочу делать экспорт по умолчанию в моих счетах. Маршрутизатор.
Я пытался :
Я пытался изменить способы экспорта, например, используя
module.export = accountsRouter