在我们的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 i --save-dev @ types / mocha 时,我显然与Jest冲突,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文件中使用skipLibCheck ...不是很干净。
这是我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"
}
有什么主意如何以干净的方式解决此问题?
谢谢!
答案 0 :(得分:0)
您可以通过向"types": []
添加compilerOptions
并包括除@types/jest
之外的所有类型的程序包来使您的方法可行。您可以使用"types": ["express", "node", "supertest"]
。
答案 1 :(得分:0)
对我来说是同样的错误。由于它似乎与NestJS的微服务包有关,因此我只需在依赖项中添加“ @ nestjs / microservices”,即可正常使用。
答案 2 :(得分:0)
对于那些有相同问题的人,我在following article中找到的skipCheckLib的替代方法是:
这将覆盖mocha def,并避免def重复(因为我仅使用Jest)。
虽然不如我所愿,但它仍然比 skipChekLib 选项要好。
答案 3 :(得分:0)
我们已通过发布void append_chunk (std::string &s, const uint8_t* chunk, size_t chunk_num_bytes)
{
s.append ((char *) chunk, chunk_num_bytes);
}
解决了此问题-不便之处,敬请原谅。
https://github.com/nestjs/nest/issues/2534