Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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`

Đang mở
#39 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
node.js, typescript
Lĩnh vực
databases, testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách chạy npx vitest và đọc db-setup.ts để tái hiện lỗi DB riêng lẻ. Xem lại issue execa được liên kết để hiểu bối cảnh của AbortSignalsetMaxListeners, sau đó xác minh rằng bản sửa lỗi đã chọn cho phép chạy bộ kiểm thử mà không gặp TypeError này trong môi trường jsdom.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
		}
	}
}
Ngôn ngữ chính
TypeScript
Star
221
Fork
61
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.