nodejs / nodejs/node

Inconsistent behavior across platforms when importing `node:http` after defining `Object.prototype['0']`

オープン
#60,567 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

never-stale
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

24.10.0

Platform
Microsoft Windows NT 10.0.26200.0 x64

and

Linux KContainer 5.10.0-12-amd64 #1 SMP Debian 5.10.103-1 (2022-03-07) x86_64 x86_64 x86_64 GNU/Linux
Subsystem

No response

What steps will reproduce the bug?

Hi,

The behavior can be reproduced by running the following snippet:

Object.defineProperty(Object.prototype, '0', {   
     set() {
        console.log(123);        
     }
 });

import http from "node:http"

Run this code by creating a file a.js in Both Linux and Windows and observe a difference in output.

How often does it reproduce? Is there a required condition?

File extension must be .js
Use import http from "node:http" instead of const http = require('http');

What is the expected behavior? Why is that the expected behavior?

Code should give same output when run in both Linux and Windows

What do you see instead?

Linux:

root@KContainer:~/git/run/test# node test.js
123
(node:1547) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/c01kele/git/run/test/test.js is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /home/c01kele/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)
123
123
123

Windows:

PS D:\HIWI\RESULTS\31_10_2025> node .\test.js
PS D:\HIWI\RESULTS\31_10_2025> 

If you use const http = require('http'); instead of import http from "node:http", both Linux and Windows give no output.

Additional information

No response

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

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

はじめの一歩

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

調査の方向性

まず、報告された Linux および Windows 環境で node:http インポートを使って issue の a.js 再現コードを実行し、その後 require('http') のケースと比較します。プラットフォーム間の違いに関係する組み込みモジュールのインポートパスを追跡します。再現コードを変更せずに、両方のプラットフォームで同じ出力が生成されれば完了です。

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

評価

技術スタック
javascript, node.js
領域
backend, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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