nodejs / nodejs/node

createRequire does not respect deleting module from require.cache

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

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

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

説明

Version

v23.10.0

Platform
Microsoft Windows NT 10.0.26100.0 x64
Subsystem

No response

What steps will reproduce the bug?

mod.js

console.log('in mod.ts')

testcase.js

import { createRequire } from 'module'
const require = createRequire(import.meta.url)

require('./mod.js?1')

const key = Object.keys(require.cache)[0]
delete require.cache[key]

require('./mod.js?2')
How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?
in mod.ts
in mod.ts
What do you see instead?
in mod.ts
Additional information

I traced it to this line, which just fully ignores source.

https://github.com/nodejs/node/blob/eab0fe264bf5e7e105827651bbb6a895354aa9c3/lib/internal/modules/esm/loader.js#L390-L391

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

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

はじめの一歩

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

調査の方向性

再現コードの testcase.js と mod.js から始め、次に、報告で source が無視されているとされている lib/internal/modules/esm/loader.js の 390-391 行付近を調べます。Windows または同等の Node.js 環境で testcase を実行し、require.cache の削除が 2 回目のクエリにどのような影響を与えるかを追跡します。期待されるメッセージが 2 回表示されれば完了です。

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

評価

技術スタック
javascript
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

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

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