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

🐛[BUG] antd.xxx 语法在 nextjs 中不起作用。 #8134

Closed
LengYXin opened this issue Jan 30, 2024 · 6 comments
Closed

🐛[BUG] antd.xxx 语法在 nextjs 中不起作用。 #8134

LengYXin opened this issue Jan 30, 2024 · 6 comments

Comments

@LengYXin
Copy link
Contributor

LengYXin commented Jan 30, 2024

🐛 bug 描述

提交PR 更改一下?
image
image
image

📷 复现步骤

🏞 期望结果

💻 复现代码

© 版本信息

  • ProComponents 版本: [e.g. 4.0.0]
  • umi 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

🚑 其他信息

@chenshuai2144
Copy link
Contributor

值得注意是的百分之二十的问题都可以用重装依赖来解决,所以你可以尝试一下:
删除 'node_modules' 文件夹 -> 删除 'package-lock.json'或 'pnpm-lock.yaml' 文件 -> 运行 'pnpm install' 或 'npm install' 命令

问题描述中提到了在nextjs中使用antd.xxx语法不起作用的问题,可能的解决方案如下:

  1. 确保antd和相关依赖包已经正确安装,并且版本兼容。可以使用npm ls antd或者yarn list antd来查看antd及其依赖的版本。

  2. 检查是否在nextjs的_app.js或者其他需要引入antd的文件中正确引入了antd的样式文件。在_next.js中,可以在_app.js文件中引入antd的样式文件,例如:import 'antd/dist/antd.css'

  3. 检查是否正确引入了antd组件。在使用antd组件之前,需要先导入相应的组件,例如:import {Button} from 'antd'

  4. 如果还是无法解决问题,可以尝试将antd的babel配置加入到nextjs的配置文件中。在next.config.js文件中,添加如下代码:

module.exports = {
  ...
  webpack: (config) => {
    config.module.rules.push({
      test: /\.(png|jpe?g|gif|svg)$/i,
      use: [
        {
          loader: 'file-loader',
          options: {
            publicPath: '/_next',
            name: 'static/media/[name].[hash].[ext]',
          },
        },
      ],
    });
    return config;
  },
  ...
};
  1. 如果还是无法解决问题,可以尝试使用antd的按需加载机制,避免引入整个antd库。可以使用babel-plugin-import插件按需加载antd组件。在.babelrc或babel.config.js文件中添加如下配置:
{
  "plugins": [
    ["import", { "libraryName": "antd", "style": "css" }]
  ]
}

综上所述,以上是一些可能的解决方案,根据具体的问题和环境情况选择适合自己的解决方案。

Copy link

Hello @LengYXin. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please 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!

你好 @LengYXin,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请务必提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

@chenshuai2144
Copy link
Contributor

我删除了一下。

@MyZest
Copy link

MyZest commented Mar 21, 2024

解决了吗?

"@ant-design/cssinjs": "1.18.4",
"@ant-design/icons": "5.3.3",
"@ant-design/pro-components": "2.6.51",
"antd": "5.15.2",
"next": "14.1.0",

还是会报错 

```js

✓ Compiled in 5.4s (7560 modules)
⨯ node_modules/@ant-design/pro-form/lib/components/FieldSet/index.js (24:21) @ Group
⨯ TypeError: Cannot read properties of undefined (reading 'Group')

@s875515
Copy link

s875515 commented Apr 4, 2024

解决了吗?

"@ant-design/cssinjs": "1.18.4",
"@ant-design/icons": "5.3.3",
"@ant-design/pro-components": "2.6.51",
"antd": "5.15.2",
"next": "14.1.0",

还是会报错 

```js

✓ Compiled in 5.4s (7560 modules) ⨯ node_modules/@ant-design/pro-form/lib/components/FieldSet/index.js (24:21) @ Group ⨯ TypeError: Cannot read properties of undefined (reading 'Group')

[email protected] works for me.

@onefeng123
Copy link

image
主要是这个原因造成的吧

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

No branches or pull requests

5 participants