Microsoft/TypeScript

Allow `import.meta.url` when `module` is `node16` or `node18`

Open

#61,441 创建于 2025年3月17日

在 GitHub 查看
 (2 评论) (3 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: Node ESMHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

import.meta' meta-property '--module' option 'es2020' 'es2022' 'esnext' 'system' 'node12' 'nodenext'

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about the module option

⏯ Playground Link

https://www.typescriptlang.org/play/?moduleResolution=99&target=99&module=100&ts=5.8.2#code/MYewdgziA2CmB00QHMAUBLAtgBxAJwBd5NYCBDeAVz2gEoBuAWACgg

💻 Code

console.log(import.meta.url);

🙁 Actual behavior

When setting the module option to node16 or node18 you get the error message:

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.

🙂 Expected behavior

node16 and node18 should be supported. import.meta.url is available in those versions of Node and it makes no sense that this setting would say that it's available in Node 12 and the latest version of Node, but not the intermediate versions of Node.

Additional information about the issue

No response

贡献者指南