next.js: failed to build custom less files in `with-ant-design-less` sample with `target: serverless`
Bug report
Describe the bug
In the case using target: 'serverless' flag in next.config.js, the with-ant-design-less sample code build failed.
$ yarn build
yarn run v1.17.3
$ next build
Creating an optimized production build ...
> Using external babel configuration
> Location: "/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.babelrc"
Compiled with warnings.
./node_modules/component-classes/index.js
Module not found: Can't resolve 'indexof' in '/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/node_modules/component-classes'
> Build error occurred
TypeError: (0 , _styleChecker.default) is not a function
at Object.g5iu (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:37583:55)
at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
at Object.3PeW (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:3977:36)
at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
at Object.lbd2 (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:42120:36)
at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
at Module.ILaR (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:15153:18)
at __webpack_require__ (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:23:31)
at /Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:91:18
at Object.<anonymous> (/Users/bko/data/dev/_projects/next-with-ant-design-less-failed/.next/serverless/pages/index.js:94:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
To Reproduce
- Go to ‘https://github.com/bokuo-okubo/next-with-ant-design-less-failed’
yarn- next => working fine
- next build => Error
(also in the case remove target: 'serverless' flag, build works fine.)
Expected behavior
I tried to build with the check condition also options.dev flag, it works fine.
In the case of using target: 'serverless' mode, config.externals contain the amp-toolbox-optimizer, so the something wrong around there.
Screenshots

- dump the option in the build time

System information
- OS: macOS, Mojave, Version 10.14.5
- Browser (if applies) [e.g. chrome, safari]
- next version: “9.0.2”
- package.json
-
{ "name": "next-with-ant-design-less-failed", "version": "0.1.0", "private": true, "scripts": { "dev": "node server.js", "build": "next build", "start": "cross-env NODE_ENV=production node server.js" }, "dependencies": { "antd": "^3.20.7", "babel-plugin-import": "^1.12.0", "cross-env": "^5.2.0", "css-animation": "^1.6.0", "express": "^4.17.1", "less": "^3.9.0", "less-vars-to-js": "^1.3.0", "next": "9.0.2", "react": "16.8.6", "react-dom": "16.8.6" }, "resolutions": { "css-animation": "1.5.0" }, "devDependencies": { "@zeit/next-less": "^1.0.1", "null-loader": "^3.0.0", "style-loader": "^0.23.1" } }
-
Additional context
Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 16 (2 by maintainers)
Commits related to this issue
- fix next.js serverless error (#18541) https://github.com/zeit/next.js/issues/8151 — committed to ant-design/ant-design by ZhengYuTay 7 years ago
- fix a build error Reference: https://github.com/zeit/next.js/issues/8151#issuecomment-527385664 — committed to dev-protocol/stakes.social by aggre 7 years ago
- Added page: How it works (#140) * create header as a shared component * styling use CSS Grid * move header component to organisms * create hot-it-works page * remove props * add a link... — committed to dev-protocol/stakes.social by aggre 7 years ago
- Fix for stylechecker null-loader Fixes issue when encountering: ```cli > Build error occurred TypeError: (0 , _styleChecker.isStyleSupport) is not a function ``` See: https://github.com/vercel... — committed to sitch/next-plugin-antd-less by sitch 6 years ago
Just found the solution, at the
next.confg.jsChange the regex toconst antStyles = /(antd\/.*?\/style).*(?<![.]js)$/;then everything will work. Thestylecheckerfile was being null-loaded and cause problems. The regex make sure to include files that dont end withjsextensionHave the same issue with the repo provided. Not entirely sure why Typography from ant design is breaking the build. Removing it will resolve the issue but it’s not ideal
Update, found out that when I use Typography component, such as Typography.Text (from ant design), this error occurs. I’m not quite sure how to resolve this, which means not being able to use this component entirely.