nodejs / nodejs/node

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

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

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

never-stale
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
272

Mô tả

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

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

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu bằng cách chạy bản tái hiện a.js của issue với import node:http trong các môi trường Linux và Windows được báo cáo, sau đó so sánh với trường hợp require('http'). Truy vết đường dẫn import của mô-đun tích hợp liên quan đến khác biệt giữa các nền tảng; hoàn thành khi cùng một đầu ra được tạo ra trên cả hai nền tảng mà không thay đổi bản tái hiện.

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

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
backend, operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

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.