ant-design / ant-design/pro-components
next.js 引入 antd 报错 SyntaxError: Cannot use import statement outside a module
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 1.4k
- Avg merge
- 10h 44m
- Merged PRs (30d)
- 3
Description
问题: next.js 引入 antd 报错 SyntaxError:无法在模块外使用导入语句
代码:
`
pagejson版本
{"name": "next-app","版本": "0.1.0",“私人”:真的,"类型": "模块","脚本": {"dev": "下一个dev","构建": "下一个构建","开始": "下一个开始","lint": "下一个lint"},"依赖性":{"antd": "^5.17.0","下一个": "14.2.3","反应": "^18","react-dom": "^18"},"devDependencies": {"@types/node": "^20","@types/react": "^18","@types/react-dom": "^18","eslint": "^8","eslint-config-next": "14.2.3","postcss": "^8","tailwindcss": "^3.4.1","typescript": "^5"}}`
`
pages/index.tsx文件
从“react”导入React;从'antd'导入{按钮};从'@/styles/page.module.css'导入样式const 页面:React.FC = () => {返回(
助开发者「更 轻松」地 stact~
<文章>So # 组件库
开始编码报错图片:

Contributor guide
Research direction
Reproduce the report from the provided package.json and pages/index.tsx, focusing on the import of antd and the reported SyntaxError. Check the Next.js build and development entry points first, then compare the result with the attached error image. Done means the sample page can import and render Button without this module error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100