ant-design: Followed steps of "Use modularized antd" and got an error
- I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
Steps to reproduce
- Started a new project with Next.js
- Followed the steps in the site of antd: here.
- Use babel-plugin-import
- Config of .babelrc
- Got a error of module.
What is expected?
Import components from antd without having to manually import the corresponding stylesheet. The antd babel plugin will need automatically import stylesheets.
What is actually happening?
Codesandbox
import { Row } from '../grid';
^
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/row (/sandbox/.next/server/static/development/pages/index.js:225:18)
at __webpack_require__ (/sandbox/.next/server/static/development/pages/index.js:23:31)
at Module../pages/index.js (/sandbox/.next/server/static/development/pages/index.js:140:69)
at __webpack_require__ (/sandbox/.next/server/static/development/pages/index.js:23:31)
at Object.3 (/sandbox/.next/server/static/development/pages/index.js:191:18)
at __webpack_require__ (/sandbox/.next/server/static/development/pages/index.js:23:31)
at module.exports../node_modules/antd/es/button/style/index.js (/sandbox/.next/server/static/development/pages/index.js:91:18)
at Object.<anonymous> (/sandbox/.next/server/static/development/pages/index.js:94:10)
at Module._compile (internal/modules/cjs/loader.js:778:30)
Localhost
import { Row } from '../grid';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1067:16)
at Module._compile (internal/modules/cjs/loader.js:1115:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
Environment | Info |
---|---|
antd | 4.1.0 |
React | 16.13.1 |
System | Mac OS |
Browser | Chrome |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 16 (3 by maintainers)
https://github.com/zeit/next.js/issues/5180#issuecomment-500704225
https://github.com/zeit/next.js/issues/9830
https://medium.com/anna-coding/how-to-config-ant-design-in-next-js-with-custom-theme-b704022591af
https://github.com/hanpama/next-with-antd
@smddzcy I can check this
@lucasbastianik
You can try the latest update in the article below
https://annacoding.com/article/2cU5baQMXG8SV2pbxh7kO8/How-to-config-Ant-Design--in-Next.js-with-custom-theme?