fix: remove "type":"module" that conflicted with CJS lib output, causing Node.js ESM load failure#5069
Open
Copilot wants to merge 1 commit into
Open
fix: remove "type":"module" that conflicted with CJS lib output, causing Node.js ESM load failure#5069Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
…rename rollup.config.js to .mjs Agent-Logs-Url: https://github.com/antvis/X6/sessions/a9e3906e-ec0d-4217-ad40-8cbc5472a8bd Co-authored-by: lxfu1 <31396322+lxfu1@users.noreply.github.com>
Member
|
@copilot 对用户来说是 break change 吗? |
Contributor
Author
对用户没有 breaking change。 分情况说明:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a Node.js ESM load failure caused by declaring "type": "module" while publishing CommonJS build output under lib/, and updates the UMD build config to remain ESM-compatible after removing that package-level module type.
Changes:
- Removed
"type": "module"frompackage.jsonso Node treatslib/*.jsas CommonJS. - Renamed the Rollup config to
rollup.config.mjsand updated thebuild:umdscript to use it explicitly.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| package.json | Removes package-level ESM typing and updates the UMD build script to target the .mjs Rollup config. |
| rollup.config.mjs | Provides an ESM Rollup config file compatible with running Rollup after removing "type": "module". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
package.json中声明了"type": "module",但lib/目录下的构建产物是 CommonJS 格式(使用exports和require())。Node.js 根据
"type": "module"将所有.js文件视为 ESM,因此尝试以 ESM 模式加载lib/index.js时报错:关联 Issue:#5048
修复方案
移除
"type": "module":"main": "lib/index.js"指向 CJS 产物,因此无需将所有.js文件标记为 ESM"module": "es/index.js"字段获得 ESM 产物顺带修复:将
rollup.config.js重命名为rollup.config.mjs:由于
rollup.config.js使用了 ESM 语法(import/export default),移除"type": "module"后需将其扩展名改为.mjs以继续以 ESM 模式运行。同步更新build:umd脚本指向新文件名。变更内容
package.json:移除"type": "module"字段;build:umd脚本改用rollup.config.mjsrollup.config.js→rollup.config.mjs(仅重命名,内容不变)测试
所有现有测试通过(200 个测试文件,2990 个测试用例)。