nodejs / nodejs/node

`require.resolve` regression starts from Node v12 with `paths`

Đang mở
#58,487 15 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.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

Version

v20.19.2

Platform
Darwin MacBookPro 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
Subsystem

No response

What steps will reproduce the bug?

https://github.com/JounQin/test/tree/repro/node_require_resolve_paths

Simply run node test.js

On node 10:

`resolve` npm package: <CWD>/fixtures/bar.js
`require.resolve` built-in function: <CWD>/fixtures/bar.js
How often does it reproduce? Is there a required condition?

Persist

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

There is a related old issue #29139.

What do you see instead?

On node 12+, of course including Node LTS (20+)

`resolve` npm package: /Users/JounQin/Workspaces/GitHub/test/fixtures/bar.js
node:internal/modules/cjs/loader:1404
  throw err;
  ^

Error: Cannot find module 'bar'
Require stack:
- <CWD>/test.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.<anonymous> (/Users/JounQin/Workspaces/GitHub/test/test.js:16:11)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Object..js (node:internal/modules/cjs/loader:1895:10)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<CWD>/test.js' ]
}
Additional information

I believe there is no reports because most projects use http://npmjs.com/resolve instead, and it behaviors same as Node 10-, and I'm trying to remove resolve as dependency, so I just met this issue at https://github.com/un-ts/eslint-plugin-import-x/pull/272#issuecomment-2915145320

cc @cjihrig

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

Chạy test.js của bản tái hiện được liên kết trên Node 10 và Node 12+, rồi so sánh kết quả của require.resolve khi cung cấp paths. Đọc đường dẫn CommonJS loader được hiển thị trong stack trace và issue liên quan #29139; hoàn thành khi bản tái hiện resolve fixtures/bar.js một cách nhất quán mà không cần package bên ngoài resolve.

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
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.