Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

nextjs9 加载 antd4 国际化语言包报错

nextjs版本 8.* 9.*
antd 版本 4.*

import zh_CN from 'antd/lib/locale-provider/zh_CN';

import zh_CN from 'antd/lib/locale/zh_CN';

都报如下错误
image.png

换了antd3 最新的版本也是一样的错误


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

nextjs默认把node_modules下一个js作为一个公共的js来处理,webpack就不会去分析node_modules下一个js的依赖了,会导致很多在node_modules中的依赖拿取不到,你可以尝试

 webpack(config) {
    if (config.externals) {
      const includes = [/locale/]
      config.externals = config.externals.map((external) => {
        if (typeof external !== 'function') return external
        return (ctx, req, cb) => {
          return includes.find((include) =>
            req.startsWith('.') ? include.test(path.resolve(ctx, req)) : include.test(req)
          )
            ? cb()
            : external(ctx, req, cb)
        }
      })
    }
    return config
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...