nodejs / nodejs/node

[Node 20] ESM Loaders no longer have `process.argv` access

未关闭
#48,577 5 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

loaders stale
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

Version

20.x

Platform

Darwin MacBook-Pro-2.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?
// foo.mjs
console.log('argv:', process.argv);

// bar.mjs
console.log('hello from bar', process.version);

Run:

$ node --loader ./foo.mjs bar.mjs --hello=world

Output:

$ node --loader ./foo.mjs bar.mjs --hello=world
# (node:37260) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
# (Use `node --trace-warnings ...` to show where the warning was created)
# argv: [
#   '/.../.volta/tools/image/node/18.12.1/bin/node',
#   '/.../bar.mjs',
#  '--hello=world'
# ]
# hello from bar v18.12.1

$ volta install node@20.2.0 # or any 20.x
$ node --loader ./foo.mjs bar.mjs --hello=world
# (node:37288) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
# (Use `node --trace-warnings ...` to show where the warning was created)
# argv: [ '/.../.volta/tools/image/node/20.2.0/bin/node' ]
# hello from bar v20.2.0
How often does it reproduce? Is there a required condition?

Every time.

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

Have access to process.argv

What do you see instead?

Doesn't receive any arguments beyond node path

Additional information

This is a breaking change introduced by #44710 & it was not listed in the PR notes.

Additionally, this breaking change wasn't listed in the 20.x Changelog

As indicated by https://github.com/nodejs/node/pull/44710#issuecomment-1609957745, the knowledge of this impact is assumed based on the user understanding (& awareness) of loaders now being off main thread.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用 foo.mjs 和 bar.mjs 重现 issue 中所示的 Node 18.x 和 20.x 命令。阅读链接的 #44710 讨论以及 doc/changelogs/CHANGELOG_V20.md 中的 Custom ESM Loader Hooks 部分,以了解预期行为。完成的标准是解决 process.argv 回归问题,或在适当的发行说明中记录已确认的 breaking change。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。