![](/img/trans.png)
[英]Netlify fails build for React app - Command failed with exit code 1
[英]Next build command fails: error Command failed with exit code 1
我需要在下一个项目中添加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中的加载程序较少是有问题的,因为据我所知, 蚂蚁设计需要较少的加载程序才能完成编译 。
您知道如何解决此问题吗?
使用最新的Next.js版本,第8版中存在错误
是的,似乎您的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]"
}
}
}
]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.