pro-components: 🧐[Not work in NextJS]
🧐 问题描述
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 26 (1 by maintainers)
My two cents on what worked for me:
next-transpile-modules
(all of the features ofnext-transpile-modules
are now built-in to Next.js 13.1 directly, so I wanted to get away from the deprecatednext-transpile-modules
).next.config.js
, I used the Next.js built-in transpiler to transpile the following (including therc-*
packages):import { EditableProTable } from "@ant-design/pro-table"
) instead of using the Next.jsdynamic
/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!
The creator of antd pro components is not a qualified programmer.
@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
you should import components like this
"import {Menu} from "antd/lib"
Could the maintainer of this lib give a hint? Why is this closed, I got the same error. It still exists.
@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