Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeScript::Nestgram + ConfigModule:: vanilla versions and error

Pls help to solve this problem
I’ve got vanilla nestgram framework and now i’m trying to add support of ConfigModule, but see the error "TypeError: Cannot read properties of undefined (reading ‘map’)"

the problem starts when I’m adding the line in app.module.ts
imports: [ConfigModule.forRoot()]

The problem seems in nest-gram.js (node_modules/nestgram/dist/nest-gram.js)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

static async getServices(Module) {
        const modules = Reflect.getMetadata('modules', Module) || [];
        const compiledModules = [];
        for (const module of modules) {
            let result;
            let err;
            try {
                result = await module();
            }
            catch (e) {
                // @ts-ignore
                result = module();
                err = e;
            }
            if (result) {
                try {
                    compiledModules.push(...result);
                }
                catch (e) {
                    throw new Error(err);
                }
            }
        }
        let services = Reflect.getMetadata('services', Module)

       * //=> MY FEAUTURE FOR DEBUGGING
    console.log(typeof(services))
        //MY FEAUTURE FOR DEBUGGING <=
*
    services = services.map((Service) => {
            return new Service(...compiledModules);
        });
        return services;
    }

my console.log(typeof(services)) returns
*undefined
object
*
when I add imports:[ ConfigModule.ForRoot()]
and only object if not

help pls

==================================================================================

main.ts

import { NestGram } from 'nestgram';
import { AppModule } from './app.module';


async function bootstrap(): Promise<void> {
  let KEY=process.env.TELEGRAM_BOT_KEY
  console.log(KEY)
  console.log(typeof(KEY))
  const bot = new NestGram(KEY, AppModule);
  await bot.start();
}

bootstrap();

app.module.ts

import { ConfigModule } from '@nestjs/config';
import { Module } from 'nestgram';
import { AppController } from './app.controller';
import { AppService } from './app.service';


@Module({
  controllers: [AppController],
  services: [AppService],
  imports: [ConfigModule.forRoot()]
})
export class AppModule {}

app.controller.ts

import { OnCommand, Controller } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  start(): string {
    return 'Hello, world!';
  }
}

app.service.ts

import { Service } from 'nestgram';


@Service()
export class AppService {
}

>Solution :

I would assume it would have to do with this warning on the front page of their docs:

Nestgram can’t use Nest.js modules. But you can create own modules for Nestgram 🙂

Seems you won’t be able to use @nestjs/config with this package.

From the looks of it, nestgram is heavily inspired by NestJS, and may even use Nest under the hood, but it is not interoperable with existing NestJS packages.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading