pro-components icon indicating copy to clipboard operation
pro-components copied to clipboard

next.js 引入 antd 报错 SyntaxError: Cannot use import statement outside a module

Open SojinLab opened this issue 9 months ago • 3 comments

问题: 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 = () => {返回(<div key="root" className={styles.root}><p>助开发者「更 轻松」地 stact~</p><文章><h1>So # 组件库</h1></文章><Button type={"primary"}>开始编码</Button></div>)};导出默认页面

报错图片: image

SojinLab avatar May 09 '24 13:05 SojinLab

pages/index.tsx代码:

`

import React from "react"; import { Button } from 'antd';

import styles from '@/styles/page.module.css'

const Pages: React.FC = () => { return ( <div key="root" className={styles.root}>

助开发者「更 轻松」地搭建~

So # 组件库

<Button type={"primary"}>start coding</Button> ) };

export default Pages `

package.json 文件

` { "name": "next-app", "version": "0.1.0", "private": true, "type": "module", "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "antd": "^5.17.0", "next": "14.2.3", "react": "^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" } }

`

SojinLab avatar May 09 '24 13:05 SojinLab

提错位置了? 这是 pro-components, 不是 antd

fnoopv avatar May 10 '24 08:05 fnoopv

好的,感谢回话

---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2024年05月10日 16:30 | | 收件人 | ant-design/pro-components @.> | | 抄送人 | SojinLab @.>, Author @.> | | 主题 | Re: [ant-design/pro-components] next.js 引入 antd 报错 SyntaxError: Cannot use import statement outside a module (Issue #8400) |

提错位置了? 这是 pro-components, 不是 antd

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

SojinLab avatar May 10 '24 08:05 SojinLab