0

I need to add antd to my next project. But it fails by running next build command:

Build error occurred
{ /Users/macbook/Documents/myapp/node_modules/antd/lib/style/index.css:7
body {
     ^

SyntaxError: Unexpected token {

next.config.js file

const withPlugins = require('next-compose-plugins');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
const BrotliPlugin = require('brotli-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const withImages = require('next-images');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});
if (typeof require !== 'undefined') {
  require.extensions[".css"] = file => {}; // eslint-disable-line
}
const nextConfig = {
  distDir: '_next',
  onDemandEntries: {
    maxInactiveAge: 1000 * 60 * 60,
    pagesBufferLength: 5,
  },
  webpack: (config, { dev }) => {
    !dev &&
      config.plugins.push(
        new BrotliPlugin({
          asset: '[path].br[query]',
          test: /\.js$|\.css$|\.html$/,
          threshold: 10240,
          minRatio: 0.7,
        }),
      );
    !dev &&
      config.plugins.push(
        new CompressionPlugin({
          filename: '[path].gz[query]',
          algorithm: 'gzip',
          test: /\.js$|\.css$|\.html$/,
          threshold: 10240,
          minRatio: 0.7,
        }),
      );
    return config;
  },
};

module.exports = withPlugins(
  [
    [withImages],
    [withCss],
    [
      withSass,
      {
        cssModules: true,
        cssLoaderOptions: {
          localIdentName: '[path]___[local]___[hash:base64:5]',
        },
      },
    ],
    [withBundleAnalyzer],
  ],
  nextConfig,
);

I think there is a problem with less loader in webpack because as far as I know, ant design needs less loader to have complied.

Do you have any idea how to fix this issue?

2 Answers 2

1

Use the latest Next.js version there was an error in the 8th version

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, it seems that your Webpack miss the configuration about CSS, you, probably, have to configure webpack css loader in a way like this

// Configuration of css loader to process .css files
{
  test: /\.css$/,
  use: [
    {
      loader: "style-loader"
    },
    {
      loader: "css-loader",
      options: {
        modules: {
          localIdentName: "[name]_[local]_[hash:base64]"
        }
      }
    }
  ]
},

2 Comments

Where should I put that exactly?
And also nextjs provides a plugin = > const withCss = require('@zeit/next-css'); for handling css files. which is added currently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.