`require('stream').promises` is an empty object when `stream/promises` is loaded before `stream`
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 58/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js
研究方向
The issue identifies the cycle in lib/stream/promises.js and lib/stream.js; first read those files and inspect the lazy loading change in #66311. Add a regression test that loads stream/promises before stream and checks the expected shared exports, including the behavior described for util.promisify. Done when the test passes in both load orders.
由索引模型根據 Issue 內容生成。
描述
Version
v26.13.1, v24.22.3 and v22.23.5
Platform
Linux x64 and Windows x64 (official binaries)
Subsystem
stream
What steps will reproduce the bug?
$ node -e "require('stream/promises'); console.log(Object.keys(require('stream').promises))"
[]
With stream loaded first it is fine:
$ node -e "require('stream'); require('stream/promises'); console.log(Object.keys(require('stream').promises))"
[ 'finished', 'pipeline' ]
How often does it reproduce? Is there a required condition?
Always, when stream/promises is loaded before anything has loaded stream. ESM import
and the node: specifiers behave the same.
Anything that loads stream first hides it (console.log, net, http, ...), which is
probably why it has gone unnoticed. We hit it in an application whose entry point starts
with import { pipeline } from 'node:stream/promises' while a dependency calls
stream.promises.pipeline.
What is the expected behavior? Why is that the expected behavior?
require('stream').promises === require('stream/promises') in either load order.
What do you see instead?
require('stream').promises is a different, empty object for the life of the process, so
stream.promises.pipeline(...) throws TypeError: stream.promises.pipeline is not a function.
util.promisify(stream.pipeline) is affected too: it silently returns a generic wrapper
instead of the stream/promises function, and that wrapper rejects an options object
such as { signal }.
Additional information
Cause. stream and stream/promises require each other (line numbers from v24.22.3):
lib/stream/promises.js:17runsrequire('stream')before it setsmodule.exportslib/stream.js:51runsconst promises = require('stream/promises')and captures the
still-empty exports objectlib/stream/promises.js:41then replacesmodule.exports, whichstreamnever sees
It takes two changes together: #46147 added the require('stream') line, and #45659
stopped stream being loaded during bootstrap.
Status on main. #66311 ("worker: preload streams into startup snapshot") makes
lib/stream.js load stream/promises lazily, which removes the cycle. It is a worker
startup change: it does not mention this behavior and adds no test for it, and it is not
on the v22.x, v24.x or v26.x branches.
- 主要語言
- JavaScript
- 星號
- 124k
- 分支
- 38k
- 平均合併
- 4 天 2 小時
- 30 天內合併 PR
- 266
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 69/100
維護者通常 1 天內回覆
-
fs: document readStream.start and readStream.end可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc: document the Buffer.prototype.*Slice() methods可能已有人在做 @AyushCipher 今天認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆
-
`styleText` fast path bypasses `options` and `options.validateStream` validation可能已有人在做 @GBra-4-669 於 8 天前認領。 未關閉util
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
riscv64
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
bug triage needed
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆
-
resource-submission validation-passed
難度 1/5 1 小時以內 新手友好度 82/100
hesreallyhim/awesome-claude-code#3773 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the status可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆