next.js: Next.js 9 with antd + less, yarn build get an error
QUESTION
yarn dev is work, but yarn build get an error.
> Build error occurred
{ /<PROJECT-PATH>/node_modules/antd/lib/style/index.less:1
(function (exports, require, module, __filename, __dirname) { @import './themes/index';
^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18) type: 'SyntaxError', '$error': '$error' }
error Command failed with exit code 1.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 18
- Comments: 30 (4 by maintainers)
RESOLVE
i found that with-ant-design-less can handles this error, but project/pages’s less style don’t work. so I wrote a
next-antd.config.jsto solve this problem.next.config.js
next-antd.config.js
.babelrc.js
package.json
Here are the files that works fine for me :
next.config.js
.babelrc
I think I have 😁 …
I had to move the plugin code from the
isServerblock.Just like that warnings are gone!
This issue solved here https://stackoverflow.com/questions/57542802/build-error-occurred-in-node-modules-antd-lib-style-index-css7/57543812#57543812
I have a similar problem with
@ant-design/layoutpackage. I’ve slowed the problem by using dynamic imports. Example: https://github.com/8iq/nodejs-hackathon-boilerplate-starter-kit/tree/f3779ff2ffd7b70ed98ad0e998923971372b7907/apps/_example04antproOr master branch: https://github.com/8iq/nodejs-hackathon-boilerplate-starter-kit/tree/master/apps/_example04antpro
because server don’t know
*.less, just browser know it. so we need to deal with this.As far as I know, less has not been added to the next9 box yet, and therefore it will not be possible to work with less without configuring the next.config
@maotora In fact, I am very dissatisfied with the plugin ecosystem of next.js, it is like a black box, and there are many bugs. If it is as easy to use as Gatsby’s plugin, there will be no problems. So I wrote this part of webpack independently and treat it like normal webpack. (Of course, this is also troublesome for people without webpack configuration experience. Also, you need to pay attention to the css-loader version and pay attention to package.json)
source: https://github.com/SolidZORO/leaa/blob/legacy-www/packages/leaa-www/tools/next/next-webpack.js
@maotora I haven’t written next.js code for a while, you may need to debug it yourself. 😭
you can see here. https://github.com/SolidZORO/leaa/blob/legacy-www/packages/leaa-www/tools/next/next-webpack.js
updated 2020-01-12.
because next-less has too many black box details, I configured webpack directly. https://github.com/SolidZORO/leaa/blob/legacy-www/packages/leaa-www/tools/next/next-webpack.js