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

nextjs引入antd/es/button报错Cannot use import statement outside a module #43233

Closed
homestylew opened this issue Jun 27, 2023 · 10 comments
Closed
Labels

Comments

@homestylew
Copy link

homestylew commented Jun 27, 2023

Reproduction link

http://www.baidu.com

Steps to reproduce

nextjs项目中:

import Button from "antd/es/button"
function App() {
  return (<div>
    <Button>TEST</Button>
  </div>)
}
export default App

报错:Cannot use import statement outside a module

What is expected?

不报错

What is actually happening?

报错:Cannot use import statement outside a module

Environment Info
antd 5.6.0
React 18.2.0
System win10
Browser chrome 114.0.5735.134
@homestylew
Copy link
Author

还有个问题就是,nextjs引入antd以后,antd组件的样式会先显示默认的样式,然后再显示antd的样式,页面有一个跳跃的过程,体验非常差。
请问怎么能解决这个问题?

@arvinxx
Copy link
Contributor

arvinxx commented Jun 28, 2023

不引入 es 就好了呀,import { Button } from 'antd'

@arvinxx
Copy link
Contributor

arvinxx commented Jun 28, 2023

还有个问题就是,nextjs引入antd以后,antd组件的样式会先显示默认的样式,然后再显示antd的样式,页面有一个跳跃的过程,体验非常差。

原因是样式没插入。解决方案参考官网的样式抽取 https://ant-design.antgroup.com/docs/react/customize-theme-cn#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%B8%B2%E6%9F%93 ,或者用 antd-style 一站式解决

@MadCcc
Copy link
Member

MadCcc commented Jun 28, 2023

不引入 es 就好了呀,import { Button } from 'antd'

+1

@MadCcc MadCcc closed this as completed Jun 28, 2023
@abstain23
Copy link

还有个问题就是,nextjs引入antd以后,antd组件的样式会先显示默认的样式,然后再显示antd的样式,页面有一个跳跃的过程,体验非常差。

原因是样式没插入。解决方案参考官网的样式抽取 https://ant-design.antgroup.com/docs/react/customize-theme-cn#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%B8%B2%E6%9F%93 ,或者用 antd-style 一站式解决

按照这个文档上的来的,把所有的css整体导出,还是没有解决闪烁问题,next13.4 antd 5.6.0

@hengkx
Copy link
Member

hengkx commented Jul 4, 2023

奇怪 我没 我没es引入也报错

Module not found: Can't resolve 'antd/es/ConfigProvider'

移除ConfigProvider后 报相同的错误

@yoyo837
Copy link
Contributor

yoyo837 commented Jul 4, 2023

奇怪 我没 我没es引入也报错

Module not found: Can't resolve 'antd/es/ConfigProvider'

移除ConfigProvider后 报相同的错误

vercel/next.js#52148

@afc163
Copy link
Member

afc163 commented Jul 4, 2023

@hengkx 没在钉钉群里?

@hengkx
Copy link
Member

hengkx commented Jul 4, 2023

在 这个先发的

@morganney
Copy link

You publish an ES variant in the es folder, however you never properly define this package is "type": "module" so ES consumers will get the SyntaxError: Cannot use import statement outside a module when using your package. I do not think defining the module field in your package.json is sufficient. If you want to support ES and CJS distributions, you should provide a "type": "module" field in an es/package.json file that overrides the root one.

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

No branches or pull requests

9 participants