rabbitmq文件ts检查无法通过
tree-lock opened this issue · comments
项目未做任何修改,
运行环境
yarn
docker-compose up -d
# 修改数据库的操作做了,这里忽略不写
yarn dev
然后就报错了。
如下第四行所示
// src/app/service/rabbitmq.ts > RabbitmqService > connect
async connect() {
// 创建连接
// @ts-ignore 这一行必须添加忽略注释才能通过
this.connection = await amqp.connect(this.rabbitmq.url);
// 创建 channel
this.channel = await this.connection.createChannel();
// 绑定队列
await this.channel.assertQueue('my-queue', {
exclusive: true,
autoDelete: true,
});
// 绑定交换机
await this.channel.bindQueue('my-queue', 'my-exchange', 'create');
return this.connection;
}
错误提示
[ Midway ] start error: ⨯ Unable to compile TypeScript:
src/app/service/rabbitmq.ts(29,5): error TS2740: Type 'IAmqpConnectionManager' is missing the following properties from type 'Connection': createConfirmChannel, off, removeAllListeners, setMaxListeners, and 6 more.
我对rabbitmq使用不多,也不知道这是个什么情况,但项目刚运行就报错。使用是docker安装的环境,忽略类型检查之后就能正常通过。
看了一些type类型定义,确实接口是对不上的,但amqp里有一个 connection 的 getter ,类型是 connection 所以能对上,但是它是 undefined 。
用 yarn 安装有时候可会丢包,你 npm install
下再试试,你看看在 vscode
里面有木有 error 的提示
是否与这个相关 midwayjs/midway#1253
npm install
直接出现了依赖问题,甚至无法正常地安装依赖项。
➜ service-mw2 git:(master) ✗ yarn clean
yarn run v1.22.11
$ rm -rf node_modules package-lock.json yarn.lock
Done in 2.43s.
➜ service-mw2 git:(master) ✗ ls
CHANGELOG.md README.md docker-compose.yml logs run src tsconfig.json
LICENSE commitlint.config.js jest.config.js package.json sonar-project.properties test typings
➜ service-mw2 git:(master) ✗ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: ts-jest@27.0.5
npm ERR! Found: @types/jest@26.0.24
npm ERR! node_modules/@types/jest
npm ERR! dev @types/jest@"^26.0.24" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @types/jest@27.0.1
npm ERR! node_modules/@types/jest
npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/xmo/.npm/_logs/2021-09-06T07_39_35_555Z-debug.log
rm -rf node_modules 了么
npm install
直接出现了依赖问题,甚至无法正常地安装依赖项。➜ service-mw2 git:(master) ✗ yarn clean yarn run v1.22.11 $ rm -rf node_modules package-lock.json yarn.lock Done in 2.43s. ➜ service-mw2 git:(master) ✗ ls CHANGELOG.md README.md docker-compose.yml logs run src tsconfig.json LICENSE commitlint.config.js jest.config.js package.json sonar-project.properties test typings ➜ service-mw2 git:(master) ✗ npm install npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: ts-jest@27.0.5 npm ERR! Found: @types/jest@26.0.24 npm ERR! node_modules/@types/jest npm ERR! dev @types/jest@"^26.0.24" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5 npm ERR! node_modules/ts-jest npm ERR! dev ts-jest@"^27.0.4" from the root project npm ERR! npm ERR! Conflicting peer dependency: @types/jest@27.0.1 npm ERR! node_modules/@types/jest npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5 npm ERR! node_modules/ts-jest npm ERR! dev ts-jest@"^27.0.4" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /home/xmo/.npm/_logs/2021-09-06T07_39_35_555Z-debug.log
我试了下, Node.js 14.17.6 可以正常 npm install
npm install
直接出现了依赖问题,甚至无法正常地安装依赖项。➜ service-mw2 git:(master) ✗ yarn clean yarn run v1.22.11 $ rm -rf node_modules package-lock.json yarn.lock Done in 2.43s. ➜ service-mw2 git:(master) ✗ ls CHANGELOG.md README.md docker-compose.yml logs run src tsconfig.json LICENSE commitlint.config.js jest.config.js package.json sonar-project.properties test typings ➜ service-mw2 git:(master) ✗ npm install npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: ts-jest@27.0.5 npm ERR! Found: @types/jest@26.0.24 npm ERR! node_modules/@types/jest npm ERR! dev @types/jest@"^26.0.24" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5 npm ERR! node_modules/ts-jest npm ERR! dev ts-jest@"^27.0.4" from the root project npm ERR! npm ERR! Conflicting peer dependency: @types/jest@27.0.1 npm ERR! node_modules/@types/jest npm ERR! peerOptional @types/jest@"^27.0.0" from ts-jest@27.0.5 npm ERR! node_modules/ts-jest npm ERR! dev ts-jest@"^27.0.4" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /home/xmo/.npm/_logs/2021-09-06T07_39_35_555Z-debug.log我试了下, Node.js 14.17.6 可以正常 npm install
是 npm 版本的问题,刚刚实验了一下,npm v6 是可以正常安装依赖的, npm v7 则会依赖报错。
还没测试 Node.js 15.x 的版本,之前 midway 有些功能还不支持,在重构中呢