我现在正在学习nestjs,但是遇到了这个错误。我不知道我是否做错了什么。有人能帮助我吗?
错误说明如下:
节点模块/@nestjs/护照/测试/公共/jwt.策略。ts:3:34 -错误TS 2307:找不到模块“../../lib”或其相应的类型声明。
3从'../../lib'导入{护照策略};
我使用PassportStrategy的文件在这里:
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'),
});
}
}
您可以在下面查看我的依赖项:
"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"
},
2条答案
按热度按时间pftdvrlh1#
尝试这样做:
1.卸载软件包
npm uninstall -S @nestjs/passport passport
1.重新安装软件包
npm i --save @nestjs/passport passport
并安装@types/passport-local
npm install @types/passport-local
cig3rfwq2#
问题是我是哑巴。当我导入我的JwtStrategy到我的auth.模块时,我导入了错误的JwtStrategy:
相反,我导入了自己的JwtStrategy,问题得到了解决