Cannot find module 'passport' or its corresponding type declarations

Viewed 10674

I am using @nestjs/passport. After running npm run start:dev I got an error, but the editor doesn't show an error

node_modules/@nestjs/passport/dist/passport/passport.serializer.d.ts:1:27 - error TS2307: Cannot find module 'passport' or its corresponding type declarations.

1 import * as passport from 'passport';

Input Code:

import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { UserRepository } from './user.repository';
import { JwtModule } from '@nestjs/jwt';


@Module({
  imports:[
    PassportModule.register({defaultStrategy:'jwt'}),
    JwtModule.register({
      secret: 'topSecret51',
      signOptions:{
        expiresIn:3600,
      },
    }),
    TypeOrmModule.forFeature([UserRepository]),
  ],
  controllers: [AuthController],
  providers: [AuthService],
})
export class AuthModule {}

Any idea what the problem could be?

4 Answers

I had the same problem. But I did a rebuild and everything worked. Removed the dist folder and then start again

rm -r dist
npm run start:dev

this error occurs due to the node version. if you got this, update node version and reinstall passport module using npm i --save @nestjs/passport passport

Same issue here.

Solved it with npm i @types/passport --save

Had the same problem, I solved it by running $ npm i --save @nestjs/passport passport.

Related