Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: rxjs_1.lastValueFrom is not a function

I am building an api using nestjs. After adding the typeorm and pg dependencies and adding the TypeOrmModule.forRoot({}) code in app.module.ts like shown below.

import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { CoffeesModule } from './coffees/coffees.module';  @Module({   imports: [CoffeesModule, TypeOrmModule.forRoot({     type: 'postgres',     host: 'localhost',     port: 5432,     username: 'postgres',     password: 'xxx',     database: 'postgres',     autoLoadEntities: true,     synchronize: true   })],   controllers: [AppController],   providers: [AppService], }) export class AppModule { }  

I get an error TypeError: rxjs_1.lastValueFrom is not a function with but no error when I exclude TypeOrmModule.forRoot({}).

What could be the reason for the error ?

like image 712
npkp Avatar asked Jul 09 '21 13:07

npkp


2 Answers

If you're using Nest v8, RxJS version 7 is used, which no longer has a toPromise() method for Observables, so Nest uses the lastValueFrom method instead. If you're receiving this error, you probably need to update your rxjs dependency to >7.

npm i rxjs@^7 yarn add rxjs@^7 pnpm i rxjs @^7 

Pick your flavor of package manager and have at it.

In the last update of NestJS, when is used cli to initialization of project this error is throw.

like image 150
Jay McDoniel Avatar answered Sep 20 '22 15:09

Jay McDoniel


The real answer

The issue is conflict with nest version.. anyone who see this - just make sure all your nestJs packages are of version 7 or 8 - don't mix them. especially those:

  • @nestjs/common
  • @nestjs/core
  • @nestjs/typeorm

from here: https://github.com/nestjs/nest/issues/7468#issuecomment-876174870

like image 36
Yitzchak Avatar answered Sep 18 '22 15:09

Yitzchak