Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to build custom less files in with-ant-design-less sample with target: serverless #8151

Closed
bokuo-okubo opened this issue Jul 29, 2019 · 16 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@bokuo-okubo
Copy link

bokuo-okubo commented Jul 29, 2019

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

  1. Go to 'https://github.com/bokuo-okubo/next-with-ant-design-less-failed'
  2. yarn
  3. next => working fine
  4. 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.

https://github.com/bokuo-okubo/next-with-ant-design-less-failed/blob/4ceee6c40d3a3e52ef52407715b3a056c03f9605/next.config.js#L34

In the case of using target: 'serverless' mode, config.externals contain the amp-toolbox-optimizer, so the something wrong around there.

Screenshots

Screenshot 2019-07-29 08 37 21


  • 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.

@d3vhound
Copy link

d3vhound commented Aug 6, 2019

yep, encountering the same problem

@skenan
Copy link

skenan commented Aug 7, 2019

same problem here

@Timer Timer added good first issue Easy to fix issues, good for newcomers help wanted labels Aug 15, 2019
@enochN
Copy link

enochN commented Aug 17, 2019

Tried working on this as my first issue.
So it seems the issue has to do with some dependencies of antd (css-animation, rc-animate, rc-select and rc-table) which make use of the library component-classes@^1.26. This library seems to try to import a dependency indexof which is not declared as a dependency in it's package.json.

Adding "indexof": "0.0.1" to the dependencies of the "with-ant-design" and "with-ant-design-less" example projects helps resolve the issue.

Would that suffice as a solution to this problem?

@skenan
Copy link

skenan commented Aug 23, 2019

@enochN did you test on https://github.com/bokuo-okubo/next-with-ant-design-less-failed? I still get the problem:TypeError: (0 , _styleChecker.default) is not a function

@enochN
Copy link

enochN commented Aug 24, 2019

So when I go through the step to reproduce, I got two unrelated errors.
First was a failure to resolve react-ssr-prepass. After adding that, there was one error about a failure to resolve styled-components and then the main error in question, failure to resolve indexof.

Since the errors involving react-ssr-prepass and styled-components do not occur in the with-ant-design-less repo, I think it's fair to just add those packages to resolve them and isolate the problem at hand.

Now when I apply my proposed solution of adding the indexof package to the bokuo-okubo's repo, the solution works. You can find my efforts here.

@aaazureee
Copy link

aaazureee commented Aug 25, 2019

@skenan I got the same problem when using ant design with nextjs. I run npm run build locally and it works fine, but when it comes to deployment, the error:

{ TypeError: (0 , _styleChecker.default) is not a function
Aug 26 2019 02:23:11:672 | ...package.json | at Object.g5iu (/tmp/7cfada92/.next/serverless/pages/sculptures.js:34883:55)
Aug 26 2019 02:23:11:672 | ...package.json | at webpack_require (/tmp/7cfada92/.next/serverless/pages/sculptures.js:23:31)
Aug 26 2019 02:23:11:672 | ...package.json | at Object.3PeW (/tmp/7cfada92/.next/serverless/pages/sculptures.js:3357:36)
Aug 26 2019 02:23:11:672 | ...package.json | at webpack_require (/tmp/7cfada92/.next/serverless/pages/sculptures.js:23:31)
Aug 26 2019 02:23:11:672 | ...package.json | at Object.lbd2 (/tmp/7cfada92/.next/serverless/pages/sculptures.js:38572:36)
Aug 26 2019 02:23:11:672 | ...package.json | at webpack_require (/tmp/7cfada92/.next/serverless/pages/sculptures.js:23:31)
Aug 26 2019 02:23:11:672 | ...package.json | at Module.A69P (/tmp/7cfada92/.next/serverless/pages/sculptures.js:7252:18)
Aug 26 2019 02:23:11:672 | ...package.json | at webpack_require (/tmp/7cfada92/.next/serverless/pages/sculptures.js:23:31)
Aug 26 2019 02:23:11:672 | ...package.json | at /tmp/7cfada92/.next/serverless/pages/sculptures.js:91:18
Aug 26 2019 02:23:11:672 | ...package.json | at Object. (/tmp/7cfada92/.next/serverless/pages/sculptures.js:94:10) type: 'TypeError', '$error': '$error' }

occurs to me. Have you found a way to fix this?

@aaazureee
Copy link

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.

@enochN
Copy link

enochN commented Aug 25, 2019

@aaazureee Could you try adding "indexof": "0.0.1" to your dependencies? Doing that worked for the sample projects I tested with.

@thongdong7
Copy link

@enochN I cloned your project and run the build command, the issue TypeError: (0 , _styleChecker.default) is not a function still happen.

The value _styleChecker is {default: {}}.

@enochN
Copy link

enochN commented Aug 25, 2019

Oh okay. I must be doing something wrong in my environment then. Will investigate further. Thanks

@aaazureee
Copy link

The weird thing is that my npm run build locally is working fine, but when deployed to zeit, the build log shows the error above.

@aaazureee
Copy link

Update: I fixed this by using next@canary instead, no more error during deployment build log.

@ZhengYuTay
Copy link

Have 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

@ZhengYuTay
Copy link

Just found the solution, at the next.confg.js
Change the regex to
const antStyles = /(antd\/.*?\/style).*(?<![.]js)$/;
then everything will work.
The stylechecker file was being null-loaded and cause problems. The regex make sure to include files that dont end with js extension

@Timer
Copy link
Member

Timer commented Jan 21, 2020

Duplicate of #9830

@Timer Timer marked this as a duplicate of #9830 Jan 21, 2020
@Timer Timer closed this as completed Jan 21, 2020
aggre added a commit to dev-protocol/stakes.social that referenced this issue May 1, 2020
abyssparanoia pushed a commit to dev-protocol/stakes.social that referenced this issue May 2, 2020
* 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 button to MainHeader

* change link size to large

* improve how-it-works page

* improve header's css

* update information on how-it-works

* fix a build error

Reference: vercel/next.js#8151 (comment)
sitch added a commit to sitch/next-plugin-antd-less that referenced this issue May 5, 2021
Fixes issue when encountering:
```cli
> Build error occurred
TypeError: (0 , _styleChecker.isStyleSupport) is not a function
```

See: vercel/next.js#8151 (comment)
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

9 participants