简体   繁体   中英

NestJS can't connect module with mongo schema

I use MongoDB and NestJs. When I connect the entity module to another module it throws error. How can I fix it?

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'
  ]
}

Repository with full code

Entity module

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 {}

Like recommended in comments, changing path from src/entities/user/account.module on ../../entities/user/account.module has helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM