fetch: errors from Node's bundled fetch have an empty stack

オープン 初心者向け
#6,115 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@MIbtehajNasar がすでに取り組んでいます。

2026年10月29日 から。

  • #6116 @MIbtehajNasar による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js
領域
backend

調査の方向性

index-fetch.js を開き、__filename が未定義の場合に使われるフォールバック分岐と、issue で説明されている Error.captureStackTrace の呼び出しを調べます。V8 が利用可能なスタックフレームを取得できるよう、コンストラクターオプションを削除し、再現例に示されているように Node に組み込まれた fetch のエラーに呼び出し元のフレームが含まれることを確認します。

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

説明

Bug Description

Every error Node's built-in fetch rejects with has an empty stack: just the Name: message line, no frames. This started with #4812.

The cause is the fallback branch in index-fetch.js, taken when __filename is undefined, as in Node's bundled copy:

} else if (err && typeof err === 'object') {
  Error.captureStackTrace(err, module.exports.fetch)
}

This runs inside the .catch callback, where fetch is no longer on the stack. When V8 can't find the constructorOpt frame it records no frames, so the stack ends up empty. Dropping the second argument fixes it.

Reproducible By

// repro.mjs: uses Node's global fetch (undici from npm takes the other branch)
async function caller (signal) {
  await fetch('http://localhost:1', { signal })
}
await caller().catch(err => console.log(err.stack))
await caller(AbortSignal.abort(new Error('my reason'))).catch(err => console.log(err.stack))

Expected Behavior

Node 24.13.1 (undici 7.18.2):

TypeError: fetch failed
    at node:internal/deps/undici/undici:16416:13
    at async caller (file:///…/repro.mjs:2:3)
    at async file:///…/repro.mjs:4:1
Error: my reason
    at node:internal/deps/undici/undici:16416:13
    at async caller (file:///…/repro.mjs:2:3)
    at async file:///…/repro.mjs:5:1

Logs & Screenshots

Node 24.22.1 (undici 7.30.1) and 26.13.0 (undici 8.12.2):

TypeError: fetch failed
Error: my reason

Environment

macOS and Alpine Linux, both arm64. Affected: Node 24.22.1 and 26.13.0. The branch is unchanged on main.

主要言語
JavaScript
スター
7.7k
フォーク
987
平均マージ
3日 8時間
マージ済み PR(30日)
55

環境構築

はじめの一歩

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

nodejs/undici のほかの issue

nodejs/undici の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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