NestJS 无法将模块与 mongo 架构连接
NestJS can't connect module with mongo schema
我使用 MongoDB 和 NestJs。当我将实体模块连接到另一个模块时,它会抛出错误。我该如何解决?
Error: Cannot find module 'src/entities/user/account.module'
Require stack:
- /Users/programming/newList-back/src/components/auth/auth.module.ts
- /Users/programming/newList-back/src/app.module.ts
- /Users/programming/newList-back/src/main.ts
at Function.<anonymous> (internal/modules/cjs/loader.js:889:15)
at Function._resolveFilename (/Users/programming/newList-back/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
at Function._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/programming/newList-back/src/components/auth/auth.module.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Module._compile (/Users/programming/newList-back/node_modules/ts-node/src/index.ts:1455:23)
at internal/modules/cjs/loader.js:1101:10
at Object..ts (/Users/programming/newList-back/node_modules/ts-node/src/index.ts:1458:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/programming/newList-back/src/components/auth/auth.module.ts',
'/Users/programming/newList-back/src/app.module.ts',
'/Users/programming/newList-back/src/main.ts'
]
}
实体模块
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { AccountDAO } from './account.dao';
import { userAccountModelDefinition } from './account.schema';
import { AccountService } from './account.service';
@Module({
providers: [AccountService, AccountDAO],
exports: [AccountService],
imports: [ConfigModule, MongooseModule.forFeature([userAccountModelDefinition], 'users')],
})
export class AccountModule {}
正如评论中所推荐的那样,从 src/entities/user/account.module
到 ../../entities/user/account.module
更改路径很有帮助。
我使用 MongoDB 和 NestJs。当我将实体模块连接到另一个模块时,它会抛出错误。我该如何解决?
Error: Cannot find module 'src/entities/user/account.module'
Require stack:
- /Users/programming/newList-back/src/components/auth/auth.module.ts
- /Users/programming/newList-back/src/app.module.ts
- /Users/programming/newList-back/src/main.ts
at Function.<anonymous> (internal/modules/cjs/loader.js:889:15)
at Function._resolveFilename (/Users/programming/newList-back/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
at Function._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/programming/newList-back/src/components/auth/auth.module.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Module._compile (/Users/programming/newList-back/node_modules/ts-node/src/index.ts:1455:23)
at internal/modules/cjs/loader.js:1101:10
at Object..ts (/Users/programming/newList-back/node_modules/ts-node/src/index.ts:1458:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/programming/newList-back/src/components/auth/auth.module.ts',
'/Users/programming/newList-back/src/app.module.ts',
'/Users/programming/newList-back/src/main.ts'
]
}
实体模块
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { AccountDAO } from './account.dao';
import { userAccountModelDefinition } from './account.schema';
import { AccountService } from './account.service';
@Module({
providers: [AccountService, AccountDAO],
exports: [AccountService],
imports: [ConfigModule, MongooseModule.forFeature([userAccountModelDefinition], 'users')],
})
export class AccountModule {}
正如评论中所推荐的那样,从 src/entities/user/account.module
到 ../../entities/user/account.module
更改路径很有帮助。