Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Isolated DB throws this error `TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal` with `npx vitest`

オープン
#39 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
node.js, typescript

調査の方向性

まず npx vitest を実行し、db-setup.ts を読んで、単独で発生する DB の失敗を再現します。リンクされた execa issue を確認して AbortSignalsetMaxListeners の背景を把握し、その後、選択した修正によって jsdom 環境でこの TypeError なしにテストスイートを実行できることを確認します。

索引モデルが issue の本文から書いたものです。

説明

npx vitest throws the following error "TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal" with Isolated DB for testing.

A little bit of google searching landed me here, which is the root cause of the problem. You can check out the link for more context. Apparently, execa version 9 which is the current version of the package in the project relies on setMaxListeners export from node:events which throws error in jsdom environment because the AbortSignal from jsdom's AbortController is not node.js EventTarget.

I'm not exactly sure the best way to fix this problem. Of course, one option would be to downgrade execa to version 8 but not sure if that's a good idea based on this comment. However, I added this hack in the db-setup.ts file and it does work for me:

const kEventTarget = Symbol.for('nodejs.event_target') // https://github.com/nodejs/node/blob/68c9f554ffa2fab1ef3b6466c51491371f0dd158/lib/internal/event_target.js#L50

if (globalThis.window !== undefined) {
	const JSDOMAbortController = window.AbortController
	window.AbortController = class extends JSDOMAbortController {
		get signal() {
			const signal = super.signal
			if ('constructor' in signal) {
				// @ts-expect-error
				signal.constructor[kEventTarget] = true //
			} else {
				// @ts-expect-error
				signal.constructor = { [kEventTarget]: true } //https://github.com/nodejs/node/blob/68c9f554ffa2fab1ef3b6466c51491371f0dd158/lib/internal/event_target.js#L1070
			}
			return signal
		}
	}
}
主要言語
TypeScript
スター
221
フォーク
61
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。