ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.04k stars 1.29k forks source link

🧐[Not work in NextJS] #4852

Closed CheaterScript closed 2 years ago

CheaterScript commented 2 years ago

🧐 问题描述

Hi, I want to use pro-table in NextJS, but it's not work. I get error:

error - ./node_modules/@ant-design/pro-field/es/components/Checkbox/index.less
Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: node_modules\@ant-design\pro-field\es\components\Checkbox\index.js

How to fix it?

🚑 其他信息

Next.js v12.0.0

SlahserZ commented 2 years ago

same error.

simon-zhangmuye commented 2 years ago

Same error +1

simon-zhangmuye commented 2 years ago

@CheaterScript @SlahserZ Hello, do you find the solution?

ungarida commented 2 years ago

@simon-zhangmuye It does not happen using https://github.com/SolidZORO/next-plugin-antd-less but this approach uses Babel which is not compatible with https://swc.rs

jianqiao0313 commented 2 years ago

+1

weijie-he commented 2 years ago

这个问题,next.js 那边给出的方案是:“publish a compiled version of their dependency” 参考:https://nextjs.org/docs/messages/css-npm 这你们能出吗?

ziyingjing commented 2 years ago

+1问题,并没有解决,用next-plugin-antd-less插件不行

simon-zhangmuye commented 2 years ago

+1 用next-plugin-antd-less插件不行

dzcpy commented 1 year ago

有解决办法吗?

chaoky commented 1 year ago

@chenshuai2144 why was this closed? you shouldn't need a less loader to use this library, all of the styles should be pre-compiled or not bundled at all, like in atnd

worldzhy commented 1 year ago

@chenshuai2144 why was this closed? you shouldn't need a less loader to use this library, all of the styles should be pre-compiled or not bundled at all, like in atnd

The creator of antd pro components is not a qualified programmer.

goalbased commented 1 year ago

I used Antd for years recently I am trying this pro-component and I faced this issue now I see this post and I will not use this library.

dzcpy commented 1 year ago

I used Antd for years recently I am trying this pro-component and I faced this issue now I see this post and I will not use this library.

Great choice, use Mantine instead

goalbased commented 1 year ago

I used Antd for years recently I am trying this pro-component and I faced this issue now I see this post and I will not use this library.

Great choice, use Mantine instead

I think Antd is the best one now

hnan commented 1 year ago

Could the maintainer of this lib give a hint? Why is this closed, I got the same error. It still exists.

chenshuai2144 commented 1 year ago

Our recent version is no longer less, it is recommended to upgrade

hnan commented 1 year ago

Our recent version is no longer less, it is recommended to upgrade

Thanks for the reply. I'm use the lates pro components and antd v4.24.5. By recent version, do you mean antd v5 ?

hnan commented 1 year ago

It turned out to be another error (#6312) I got. And this comment fixed my problem. Thanks.

neongreen commented 1 year ago

I tried next-transpile-modules but quickly ended up in a rabbit hole. Here's how I got things to work:

dzcpy commented 1 year ago

I tried next-transpile-modules but quickly ended up in a rabbit hole. Here's how I got things to work:

So does it work now? How did you apply the patch?

neongreen commented 1 year ago

It should work now even without the patches, just use the version from master 24.12.2022 kl. 8:34 am skrev dzcpy @.***>:

I tried next-transpile-modules but quickly ended up in a rabbit hole. Here's how I got things to work:

antd 5 Next.js 13 (no idea if it changes anything though) and patches from 🐛[BUG]作为cjs模块导入的语法错误 #6338

So does it work now? How did you apply the patch?

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

ogienma commented 1 year ago

My two cents on what worked for me:

  1. I used the following package versions:
    "@ant-design/charts": "1.2.10",
    "@ant-design/icons": "^4.7.0",
    "@ant-design/plots": "^1.2.2",
    "@ant-design/pro-components": "^2.3.47",
    "@ant-design/pro-descriptions": "^2.0.37",
    "@ant-design/pro-form": "^2.4.7",
    "@ant-design/pro-list": "^2.0.40",
    "@ant-design/pro-provider": "^2.1.4",
    "@ant-design/pro-table": "^3.2.7",
    "antd": "^5.1.0",
    "next": "^13.1.0",
  1. In next.config.js, I used the Next.js built-in transpiler to transpile the following (including the rc-* packages):
transpilePackages: [
    "antd",
    "@ant-design/plots",
    "@ant-design/icons",
    "@ant-design/icons-svg",
    "@ant-design/pro-components",
    "@ant-design/pro-layout",
    "@ant-design/pro-list",
    "@ant-design/pro-descriptions",
    "@ant-design/pro-form",
    "@ant-design/pro-skeleton",
    "@ant-design/pro-field",
    "@ant-design/pro-utils",
    "@ant-design/pro-provider",
    "@ant-design/pro-card",
    "@ant-design/pro-table",
    "rc-pagination",
    "rc-picker",
    "rc-util",
    "rc-tree",
    "rc-tooltip"
  ]
  1. When importing components, I imported them "normally" (e.g., import { EditableProTable } from "@ant-design/pro-table") instead of using the Next.js dynamic/ssr: false trick.

I haven't tested all pro components with this, but so far ProTable and ProForm work. The PageHeader component does not work with this approach (same error as https://github.com/ant-design/pro-components/issues/6312), but thankfully that component is simple enough to recreate/rewrite yourself - unlike the others, it's not a very complicated component with lots of logic.

Best of luck!

dzcpy commented 1 year ago

Just tried transpilePackages config and it worked. However in multiple places it uses document.body, So it's better to put it into client side components, like for example in the new v13 app directory with 'use client' directive.

wstiehler commented 4 months ago

I resolved with the resolution apresents by https://github.com/ant-design/pro-components/issues/4852#issuecomment-1364570216

thanks

eladonline commented 2 months ago

you should import components like this "import {Menu} from "antd/lib"

NullBetaGG commented 2 months ago

você deve importar componentes como este"import {Menu} from "antd/lib" thanks brooo