-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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
Fix ESM exports #46413
Comments
Pls check for help with the framework you are using. We've already config the |
@zombieJ thanks for you answer. I am not using any framework. The You should be more respectful of people who take the time to bring problems to your attention... |
this is affecting me as well, please reopen @zombieJ |
Hi, @jer-sen @replygirl , |
Thanks for reopening this issue. I will try to help you as much as I can. Not easy to reproduce. I think the easiest thing to do is to fix the kind of errors I have listed. An easy thing to test is TS lib check. I don't know if there is a way to have an online repro but you can follow these few steps:
// package.json
{
"license": "MIT",
"dependencies": {
"antd": "*",
"react": "~18.2.0",
"typescript": "5.3.3"
},
"type": "module",
"devDependencies": {
"@types/react": "~18.2.45"
}
}
// tsconfig.json
{
"compilerOptions": {
"allowImportingTsExtensions": false,
"allowSyntheticDefaultImports": false,
"alwaysStrict": true,
"declaration": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["ESNext", "DOM"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"skipDefaultLibCheck": false,
"skipLibCheck": false,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "ESNext",
"verbatimModuleSyntax": true
}
}
// index.tsx
import "antd";
@zombieJ can you reproduce this? |
@jer-sen Please provide a repo |
@MadCcc for 3 files with 40 lines??? |
Hello @jer-sen. Please provide a online reproduction by forking codesandbox of antd@5.x or antd@4.x, or provide a minimal GitHub repository. Issues labeled by 你好 @jer-sen,我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击这里创建一个 antd@5.x 或 antd@4.x 的 codesandbox,或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。 |
@afc163 @MadCcc @zombieJ here is a repro https://codesandbox.io/p/sandbox/antd-reproduction-template-forked-9qzj6f You can download source, unzip, run |
So, we can’t see those errors when running codesandbox online? |
That's true.
|
Could you make a repo zip file that can be downloaded, unzip and run directly? Downloading from the source code may produce a different repo. |
No. Stop. I'm happy to help but please... Go on codesandbox and choose "Download Sandbox". |
Sorry for that request, I didn't notice this |
@yoyo837 did you manage to reproduce? |
No, when I run |
@yoyo837 did you:
Maybe you forgot to install modules. |
Yes ! Now it's time to fix these first issues. Most of them can be fixed by:
But you should fix all these in the tsconfig or build process of |
Hello @jer-sen. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution! 你好 @jer-sen,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。 |
Reproduction link
Steps to reproduce
Import things from
"antd"
& types from"antd/es/..."
from an ESM module with recommended (less fault-tolerant / strictest) TS config.My
tsconfig.json
contains:What is expected?
No error during development, build nor run time.
What is actually happening?
Many errors.
Origin of errors:
"antd/es/..."
must have.d.mts
or.mjs
extension, or apackage.json
containing{"type":"module"}
must be added to the folder"antd/es/..."
do not import any file from CJS exports of a module, there should not have anyimport ... from 'rc-???/lib/...';
=> import will fail if (and it would be a good thing) imported module restricts its/lib/
path to only CJS requires (exports
field inpackage.json
)"antd/es/..."
any relative import (specifier or expression) in a.d.ts
or.js
should point to a file (not a directory) and have a file extension => TS error since modules are resolved asany
/*#__PURE__*/
comment and the function call, cfantd/es/skeleton/Paragraph.js
orantd/es/list/Item.js
=> esbuild error during buildreact
) should not be imported usingimport Module from 'module'
but instead withimport * as Module from 'module'
, cfantd/es/config-provider/defaultRenderEmpty.d.ts
=> TS error withallowSyntheticDefaultImports
disabled and runtime error without a bundler that fakes a default importInteresting reading:
"module": "node16"
should support extension rewriting microsoft/TypeScript#49083 (comment)I found quite the same issues in
react-component
modules cf react-component/util#491The text was updated successfully, but these errors were encountered: