简体   繁体   中英

Im getting error while importing PassportStrategy

I am learning nestjs right now and stuck on this error. I dont know if im doing something wrong or not. Can someone help me?

error says as it follows:

node_modules/@nestjs/passport/test/common/jwt.strategy.ts:3:34 - error TS2307: Cannot find module '../../lib' or its corresponding type declarations.

3 import { PassportStrategy } from '../../lib';

file where I used PassportStrategy is here:

import { ConfigService } from '@nestjs/config';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';

export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor(config: ConfigService) {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      secretOrKey: config.get('JWT_SECRET'),
    });
  }
}

you can view my dependencies below:

  "dependencies": {
    "@nestjs/common": "^9.0.0",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/jwt": "^9.0.0",
    "@nestjs/passport": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/swagger": "^6.1.4",
    "@prisma/client": "^4.8.0",
    "argon2": "^0.30.2",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "passport": "^0.6.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "28.1.8",
    "@types/node": "^16.0.0",
    "@types/passport-jwt": "^3.0.8",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "28.1.3",
    "prettier": "^2.3.2",
    "prisma": "^4.8.0",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.7.4"
  },

Try to do this:

  1. uninstall the packages npm uninstall -S @nestjs/passport passport

  2. reinstall the packages npm i --save @nestjs/passport passport

And install @types/passport-local npm install @types/passport-local

The problem is that i am dumb. while importing my JwtStrategy to my auth.module I have imported the wrong JwtStrategy:

import { JwtStrategy } from './../../node_modules/@nestjs/passport/test/common/jwt.strategy';

Instead I imported my own JwtStrategy and problem solved

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