Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

目前的导出模式无法实现自动切换 CommonJS 和 ESModule 导入 #513

Closed
hungtcs opened this issue Apr 2, 2024 · 0 comments
Closed

Comments

@hungtcs
Copy link

hungtcs commented Apr 2, 2024

当前 package.json 中声明的导出方式,无法显示自动根据环境切换 CommonJS 和 ESModule 导入,
我发现有一些依赖此包的代码,直接使用如 import warn from 'rc-util/lib/warning'; 的方式导入,这会导致导入的代码永远是 CommonJS 格式的。

如下面的代码:
https://github.com/ant-design/ant-design-icons/blob/77062f82563607540029c31be00f22bf2359a72e/packages/icons-react/src/utils.ts#L3-L5

正确的导出方式应该是使用 exports 导出,并在使用时使用 rc-util/warning 来导入。

"exports": {
  ".": {
    "import": "./es/index.js",
    "require": "./lib/index.js",
    "types": "./es/index.d.ts"
  },
  "./*": {
    "import": "./es/*.js",
    "require": "./lib/*.js",
    "types": "./es/*.d.ts"
  },
  "./Children/*": {
    "import": "./es/Children/*.js",
    "require": "./lib/Children/*.js",
    "types": "./es/Children/*.d.ts"
  },
  "./debug/*": {
    "import": "./es/debug/*.js",
    "require": "./lib/debug/*.js",
    "types": "./es/debug/*.d.ts"
  },
  "./Dom/*": {
    "import": "./es/Dom/*.js",
    "require": "./lib/Dom/*.js",
    "types": "./es/Dom/*.d.ts"
  },
  "./hooks/*": {
    "import": "./es/hooks/*.js",
    "require": "./lib/hooks/*.js",
    "types": "./es/hooks/*.d.ts"
  },
  "./React/*": {
    "import": "./es/React/*.js",
    "require": "./lib/React/*.js",
    "types": "./es/React/*.d.ts"
  },
  "./utils/*": {
    "import": "./es/utils/*.js",
    "require": "./lib/utils/*.js",
    "types": "./es/utils/*.d.ts"
  }
},

其他

这是一项破坏性的修改,会导致其他错误导入此包的代码无法使用。

相关 Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant