Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rabbitmq文件ts检查无法通过 #95

Open
tree-lock opened this issue Sep 3, 2021 · 7 comments
Open

rabbitmq文件ts检查无法通过 #95

tree-lock opened this issue Sep 3, 2021 · 7 comments

Comments

@tree-lock
Copy link

tree-lock commented Sep 3, 2021

项目未做任何修改,

运行环境

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 。

@tkvern
Copy link
Member

tkvern commented Sep 3, 2021

用 yarn 安装有时候可会丢包,你 npm install 下再试试,你看看在 vscode 里面有木有 error 的提示

@waitingsong
Copy link
Member

是否与这个相关 midwayjs/midway#1253

@tree-lock
Copy link
Author

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: [email protected]
npm ERR! Found: @types/[email protected]
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 [email protected]
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/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   peerOptional @types/jest@"^27.0.0" from [email protected]
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

@vern-crypto
Copy link
Member

rm -rf node_modules 了么

@vern-crypto
Copy link
Member

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: [email protected]
npm ERR! Found: @types/[email protected]
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 [email protected]
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/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   peerOptional @types/jest@"^27.0.0" from [email protected]
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

@tree-lock
Copy link
Author

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: [email protected]
npm ERR! Found: @types/[email protected]
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 [email protected]
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/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   peerOptional @types/jest@"^27.0.0" from [email protected]
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 则会依赖报错。

@tkvern
Copy link
Member

tkvern commented Sep 7, 2021

还没测试 Node.js 15.x 的版本,之前 midway 有些功能还不支持,在重构中呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants