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

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

Open
SojinLab opened this issue May 9, 2024 · 3 comments

Comments

@SojinLab
Copy link

SojinLab commented May 9, 2024

问题: 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
Copy link
Author

SojinLab commented May 9, 2024

pages/index.tsx代码:

`

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

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

const Pages: React.FC = () => {
return (


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



So # 组件库



<Button type={"primary"}>start coding

)
};

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"
}
}

`

@fnoopv
Copy link
Contributor

fnoopv commented May 10, 2024

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

@SojinLab
Copy link
Author

SojinLab commented May 10, 2024 via email

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

No branches or pull requests

2 participants