Next.js server rendering, the introduction of antd.less error?

   exports = module.exports = require("../../css-loader/lib/css-base.js")(false);
      ^
Unrecognised input
      in /Users/liubin/Desktop/github/next-ssr/node_modules/antd/dist/antd.less (line 1, column 8)

ask for advice

Jun.11,2021

I also encountered the same problem. I solved the problem by
modifying webpack.config.dev.js and webpack.config.prod.js

.
  1. find test: / css$/ and change it to test: /\. (css | less) $/,
  2. add an object under the use array of the object, which is to be placed at the end of the use array. I have this problem because I didn't put it at the end
    {
    loader: require.resolve ("less-loader"),
    },
  3. .
  4. add an array entry /. (css to the exclude array | less) $/
  5. yarn run start

1. First of all, make sure that the less,less-loader dependency
2 is introduced. Modify the configuration of webpack
as follows. Compare the config file and add it. Note that the file loader, does not load the less file by default. We need to manually modify it to include it, otherwise the compiler configured above will not take effect, because the less file is not loaded at the beginning

.
module.exports = {
    ...,
    module: {
        rules: [***{
            test: /\.less$/,
            use: ["style-loader", "css-loader", "less-loader"]
        //less-loader=>css-loader=>style-loader
        }***, {
        oneOf:[
        ...,{
        loader: require.resolve('file-loader'),
              exclude: [/\.(js|mjs|jsx|ts|tsx|less)$/, /\.html$/, /\.json$/],
              options: {
                name: 'static/media/[name].[hash:8].[ext]',
              },
        }
        ]
        }
        ]
    }


http://www.liuweibo.cn/p/206

developed by next.js+antd+redux for personal websites
Menu