当尝试 require() ES 模块时,CommonJS 到 ESM 或 ESM 到 CommonJS 边缘会参与立即循环。这是不允许的,因为 ES 模块在已经被评估时无法被评估。
为了避免循环,循环中涉及的 require() 调用不应发生在 ES 模块(通过 createRequire())或 CommonJS 模块的顶层,而应在内部函数中延迟完成。
Google Translate · 此内容为自动翻译。技术术语及适用条件请以英文原文为准。
官方说明 · 原文
When trying to require() an ES Module, a CommonJS to ESM or ESM to CommonJS edge participates in an immediate cycle. This is not allowed because ES Modules cannot be evaluated while they are already being evaluated.
To avoid the cycle, the require() call involved in a cycle should not happen at the top-level of either an ES Module (via createRequire()) or a CommonJS module, and should be done lazily in an inner function.
修改记录:English prose extracted; whitespace normalized; Korean context and classified official links added. Python code examples not redistributed. 译文说明已标注为自动翻译。