nextjs版本 8.* 9.*
antd 版本 4.*
import zh_CN from 'antd/lib/locale-provider/zh_CN';
或
import zh_CN from 'antd/lib/locale/zh_CN';
都报如下错误
换了antd3 最新的版本也是一样的错误
nextjs版本 8.* 9.*
antd 版本 4.*
import zh_CN from 'antd/lib/locale-provider/zh_CN';
或
import zh_CN from 'antd/lib/locale/zh_CN';
都报如下错误
换了antd3 最新的版本也是一样的错误
我的理解是,要让webpack的loader去处理这个esModule,所以要在externals这地方判断一下,不要给他排除了
webpack: (config, { isServer }) => {
if (isServer) {
const antdLocale = /antd\/es/;
const antStyles = /antd\/.*?\/style.*?/;
const origExternals = [...config.externals];
config.externals = [
(context, request, callback) => {
if (request.match(antStyles) || request.match(antdLocale)) 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',
});
}
10 回答11.2k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.4k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
nextjs默认把node_modules下一个js作为一个公共的js来处理,webpack就不会去分析node_modules下一个js的依赖了,会导致很多在node_modules中的依赖拿取不到,你可以尝试