Nestjs-在@Nestjs/microservices依赖项中声明的mocha类型问题
嵌入@nestjs时/terminus@6.1.0在我们的nestjs项目中,一种类型的@nestjs/microservices无法识别: $>tscNestjs-在@Nestjs/microservices依赖项中声明的mocha类型问题,nestjs,Nestjs,嵌入@nestjs时/terminus@6.1.0在我们的nestjs项目中,一种类型的@nestjs/microservices无法识别: $>tsc node_modules/@nestjs/microservices/external/redis.interface.d.ts:2:23 - error TS2688: Cannot find type definition file for 'mocha'. 2 /// <reference types="mocha" />
node_modules/@nestjs/microservices/external/redis.interface.d.ts:2:23 - error TS2688: Cannot find type definition file for 'mocha'.
2 /// <reference types="mocha" />
~~~~~
Found 1 error.
node_modules/@types/jest/index.d.ts:27:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'beforeEach' must be of type 'HookFunction', but here has type 'Lifecycle'.
27 declare var beforeEach: jest.Lifecycle;
...
目前,我找到的唯一解决方法是在tsconfig.json文件中使用skipLibCheck。。。不太干净
这里是my package.json文件的dep部分:
[...]
"dependencies": {
"@nestjs/common": "^6.0.5",
"@nestjs/core": "^6.0.5",
"@nestjs/mongoose": "^6.0.0",
"@nestjs/graphql": "^6.2.1",
"@nestjs/swagger": "^3.0.2",
"@nestjs/terminus": "6.1.0",
"@godaddy/terminus": "4.1.0",
"app-root-path": "^2.2.1",
"class-transformer": "^0.2.0",
"class-validator": "^0.9.1",
"codacy-coverage": "^3.1.0",
"apollo-server-express": "^2.5.0",
"graphql": "^14.3.0",
"graphql-tools": "^4.0.4",
"js-cache": "^1.0.3",
"mongoose": "^5.4.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.4.0",
"typescript": "^3.5.2",
"winston": "^3.2.1"
},
"devDependencies": {
"@nestjs/testing": "^5.0.0",
"@types/express": "^4.0.39",
"@types/jest": "^21.1.8",
"@types/node": "^9.3.0",
"@types/supertest": "^2.0.4",
"jest": "^21.2.1",
"nodemon": "^1.14.1",
"prettier": "^1.11.1",
"supertest": "^3.0.0",
"ts-jest": "^21.2.4",
"ts-loader": "^4.1.0",
"ts-node": "^4.1.0",
"tsconfig-paths": "^3.1.1",
"tslint": "5.3.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "lib",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage"
}
你知道如何以干净的方式解决这个问题吗
谢谢 您可以通过向
编译器选项添加“类型”:[]
,并包括除@types/jest
之外的所有类型包,从而使您的方法起作用。在您的情况下,您可以使用“类型”:[“express”、“node”、“supertest”]
对我来说同样的错误。由于它似乎与NestJS的微服务包有关,我刚刚在我的依赖项中添加了“@NestJS/microservices”,现在它可以正常工作。对于那些有相同问题的人,我在
- 在我的项目中创建一个空文件覆盖/mocha/index.d.ts
- 添加到tsconfig文件“typeroot”:[“覆盖”,“节点模块/@types”]
这将覆盖mocha def并避免def重复(因为我只使用Jest)
它没有我想要的那么干净,但仍然比skipChekLib选项好。我们通过发布@nestjs解决了这个问题/microservices@6.5.1
-很抱歉给您带来不便。
我尝试了这个方法,但定义了摩卡“类型”:[“express”、“node”、“supertest”、“mocha”]
,但是运行我的e2e测试(基于Jest)将不再有效,因为它将使用摩卡类型而不是Jest(或者无法识别适合于Jest的类型)。您尝试过使用多个TSConfig吗?我使用扩展了tsconfig.js的tsconfig.build.json来运行tsc,所以我将类型放入tsconfig.build.json中。我也尝试了这个,但它对我不起作用。你在你的项目中也在使用玩笑吗?是的,我在使用玩笑,奇怪的是它对你不起作用。也许你可以尝试更新你的软件包?因为这是一个新项目,我已经更新了我的所有内容。我看到你在用Jest@21他们现在24岁了,也许这会有帮助。