node.jsresttypescriptmongoosenest

Unable to bootstrap Nest application. "TypeError: Object prototype may only be an Object or null: undefined"


Recently I wrote for myself a demo-app based on this Ahamed Foysal's example (https://www.codementor.io/foysalit/rest-api-with-mongodb-and-nest-js-hto6x5120). As you know NestJS is a very young framework and there are catastrophicaly small number of tutorials & demo-apps for learn it. So, I create all files in the project, run mongod in separate terminal window, and run app: npm run start But the app is crashed with:

Error output

enter image description here

P.S. I checked - circular references in my codebase don't exists (Vue + typescript - TypeError: Object prototype may only be an Object or null: undefined).

Any help would be greatly appreciated.


Solution

  • In database.module.ts do a

    @Module({
        components: [...databaseProviders],
        exports: [...databaseProviders],
    })
    export class DatabaseModule {}
    

    three dots are required

    Then in posts.module.ts

    @Module({
        imports: [DatabaseModule],
        controllers: [PostsController],
        components: [PostsService, ...postsProviders],
    })
    export class PostsModule {}
    

    again three dots are required

    in posts.providers.ts replace DB_CONNECTION with DB_PROVIDER

    Why three dots ? If you will look in posts.providers.ts it exports an array, and you want your module to import each provider separately, not the array.