Update Ant Design Examples for New CSS Support (9.2)
import ant-design library throw error
can you provide an example import ant-design use [RFC] css support? thanks. when i use [RFC] css support and import ant-design library, it throw error :
./node_modules/antd/lib/button/style/index.css
Global CSS cannot be imported from files other than your Custom <App>. Please move all global CSS imports to pages/_app.js.
here is my next-config.js
module.exports = {
experimental: {
css: true
},
}
Maybe not support css from node_modules, I guess.
Maybe not support css from node_modules, I guess.
if you don't use [RFC] css support , you can support css from node_modules with-css plugin.
Linking to #8626
I’d be also interested in seeing this. Our teams use antd with next-css/next-less and some hacks on top from the Next.js examples folder. That setup is quite clumsy and fragile. I’m looking forward to switching to the build-in css support, but have no clue how to deal with less in this case.
antd is a pretty popular ui framework, so I guess quite a lot of devs will benefit from a new example.
Has anyone got ant-design working with Next 9.2 yet? (without @zeit/next-css)
@stephankaag, I have used withLess to use antd v4.0.0.rc1, it works!
I'm still seeing issues with antd 4.0.
Configuration is similar to [https://levelup.gitconnected.com/lets-create-a-project-with-nextjs-antd-and-deploy-with-now-sh-e38772348312|this guide]
@stephankaag, I have used withLess to use antd v4.0.0.rc1, it works!
Of course, because that combination always worked. I am trying to make things work WITHOUT @zeit/next-css or @zeit/next-less.
Anyone has successfully integrated next 9.2 with ant design? (without next-css plugin)
@stephankaag The combination works very well (I'm using withCss combined with withLess and custom less variables), but how is your bundle size?
I have migrated to antd4. Seems like the tree shaking doesn't work as expected from v4. I'm having more than 1,3mb bundle size, where most of it are the antd icons.
According to this https://github.com/ant-design/babel-plugin-import/issues/402 the "libraryDirectory": "es" is necessary (the official with-ant-less example doesn't have it).
But adding this gives me the following error:
[ error ] /home/maciek/Dokumenty/websites/bookingapp/frontend/node_modules/antd/es/notification/index.js:3
import * as React from 'react';
^
SyntaxError: Unexpected token *
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.antd/es/notification (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10975:18)
at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31)
at Module../lib/withData.js (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:8200:78)
at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31)
at Module../pages/_app.js (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10614:71)
at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31)
at Object.0 (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10754:18)
at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31)
at /home/maciek/Dokument
@stephankaag The combination works very well (I'm using withCss combined with withLess and custom less variables), but how is your bundle size? I have migrated to antd4. Seems like the tree shaking doesn't work as expected from v4. I'm having more than 1,3mb bundle size, where most of it are the antd icons. According to this ant-design/babel-plugin-import#402 the
"libraryDirectory": "es"is necessary (the official with-ant-less example doesn't have it). But adding this gives me the following error:[ error ] /home/maciek/Dokumenty/websites/bookingapp/frontend/node_modules/antd/es/notification/index.js:3 import * as React from 'react'; ^ SyntaxError: Unexpected token * at Module._compile (internal/modules/cjs/loader.js:723:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.antd/es/notification (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10975:18) at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31) at Module../lib/withData.js (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:8200:78) at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31) at Module../pages/_app.js (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10614:71) at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31) at Object.0 (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:10754:18) at __webpack_require__ (/home/maciek/Dokumenty/websites/bookingapp/frontend/.next/server/static/development/pages/_app.js:23:31) at /home/maciek/Dokument
@chemicalkosek did you manage to resolve this? I've been running into the exact same issue on Nextjs 9.2.1
Anyone manage to resolve this issue?
Any updates to this issue?
My solution:
yarn add esm
"scripts": {
"dev": "NODE_OPTIONS=\"-r esm\" next",
"build": "NODE_OPTIONS=\"-r esm\" next build",
"start": "NODE_OPTIONS=\"-r esm\" next start"
}
@i-tengfei Wow, it's working! Thank you very much!
@i-tengfei are you using the same configuration as the example?
If not, mind posting your next.config & babelrc?
Btw I'm not using the new CSS support. What's working is next with antd4 tree shaked (tree shaking never worked with antd in the official example, because of the lack of "libraryDirectory":"es"). Bundle size cut about 700-800kb I believe. I'm still using withCss and withLess tho.
@chemicalkosek do you still see:
chunk styles [mini-css-extract-plugin]
Conflicting order between
with your setup?
Yes, I do, but afaik that's just a warning and everything works just fine. I have once researched this issue and I believe it's because you have in one component:
import { Button, Input } from 'antd'
and in another component:
import { Input, Button } from 'antd'
Supposedly it's what's creating this issue, but I'm not really sure of it You can hide those warnings, but I didn't try. I'll try tomorrow though, those can be pretty annoying. Source 1: https://github.com/webpack-contrib/mini-css-extract-plugin#remove-order-warnings Source 2: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/250 I'm very happy about the tree shaking now :) And with antd4 the icons are no longer included as they were with antd3, where the icons made like half of antd3 size. You can import icons selectively now.
Unfortunately, my experience is it's not just a warning you can just ignore. I've seen issues with components not getting styled as I've added more antd components to the page. Happens very inconsistently. Organizing imports consistently doesn't make it go away either