【问题标题】:Next build command fails: error Command failed with exit code 1下一个构建命令失败:错误命令失败,退出代码为 1
【发布时间】:2019-12-04 23:29:32
【问题描述】:

我需要将antd 添加到我的下一个项目中。但它通过运行下一个构建命令失败:

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

SyntaxError: Unexpected token {

next.config.js 文件

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,
);

我认为 webpack 中的 less loader 存在问题,因为据我所知,ant design 需要更少的 loader 才能遵守。

你知道如何解决这个问题吗?

【问题讨论】:

    标签: reactjs webpack next.js antd


    【解决方案1】:

    是的,您的 Webpack 似乎错过了有关 CSS 的配置,您可能必须以这样的方式配置 webpack css loader

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

    【讨论】:

    • 我应该把它准确地放在哪里?
    • 而且nextjs还提供了一个插件=> const withCss = require('@zeit/next-css');用于处理 css 文件。这是当前添加的。
    【解决方案2】:

    使用最新的Next.js版本第8版出现错误

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 2015-10-12
      • 2018-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多