在我们的nestjs项目中嵌入@nestjs/terminus@6.1.0时,不承认@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" />
~~~~~
Found 1 error.
当添加npm -save @types/mocha时,我显然会遇到与Jest的冲突,这是我们正在使用的测试框架.
$> tsc
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文件中使用tsconfig.json.不是很干净。
在这里,我的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"
}
知道怎么干净地解决这个问题吗?
谢谢!
发布于 2019-07-09 08:43:00
发布于 2019-07-12 22:54:16
我们已经通过@nestjs/microservices@6.5.1
的发布解决了这个问题--抱歉给您带来不便。https://github.com/nestjs/nest/issues/2534
发布于 2019-07-08 00:27:10
您可以通过将"types": []
添加到compilerOptions
并包括除@types/jest
之外的所有类型包来使您的方法工作。在您的情况下,您可以使用"types": ["express", "node", "supertest"]
。
https://stackoverflow.com/questions/56926302
复制相似问题