Afs*_*fda 2 reactjs react-dom next.js antd
升级之后react,react-dom和nextjs这个错误发生的情况:
发生构建错误/home/lenovo/.../node_modules/antd/lib/style/index.css:7 body {^
语法错误:意外令牌{位于Module._compile(internal / modules / cjs / loader.js:720:22)
在Object.Module._extensions..js(internal / modules / cjs / loader.js:788:10)在Module.load(internal / modules / cjs / loader.js:643:32){type:'SyntaxError', '$ error':'$ error'} events.js:180 throw er; //未处理的'错误'事件^错误:在processTicksAndRejections(内部/process/task_queues.js:77:11)上写入EPIPE ... internal / process / task_queues.js:75:11){errno:'EPIPE',代码:'EPIPE',syscall:'write'}错误命令失败,退出代码为1。info访问https://yarnpkg.com/en / docs / cli / run有关此命令的文档。
这是我的next.config.js:
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,
);
Run Code Online (Sandbox Code Playgroud)
你知道这是怎么回事吗?
编辑
看来蚂蚁设计存在兼容性问题,但我找到了一些资源,但没有得到!
基于Next.js存储库中的此示例 https://github.com/zeit/next.js/tree/canary/examples/with-ant-design
要解决此问题,请将这些行添加到您的next.config.js:
const nextConfig = {
webpack: (config, { isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style\/css.*?/;
const origExternals = [...config.externals];
config.externals = [ // eslint-disable-line
(context, request, callback) => { // eslint-disable-line
if (request.match(antStyles)) return callback();
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback);
} else {
callback();
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
];
config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
});
}
return config;
},
};
Run Code Online (Sandbox Code Playgroud)
该next.config.js文件的示例如下所示:
const withPlugins = require('next-compose-plugins');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
if (typeof require !== 'undefined') {
require.extensions['.css'] = file => {};
}
const nextConfig = {
webpack: (config, { isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style\/css.*?/;
const origExternals = [...config.externals];
config.externals = [ // eslint-disable-line
(context, request, callback) => { // eslint-disable-line
if (request.match(antStyles)) return callback();
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback);
} else {
callback();
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
];
config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
});
}
return config;
},
};
module.exports = withPlugins(
[
[withCss],
[
withSass,
{
cssModules: true,
cssLoaderOptions: {
localIdentName: '[path]___[local]___[hash:base64:5]',
},
},
],
],
nextConfig,
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1163 次 |
| 最近记录: |