You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Next.js中导入CommonJS模块时的i18n命名导出不存在错误?

解决CommonJS模块导入时的"Named export 'i18n' not found"错误

问题原因

你的next-i18next.config.js是CommonJS模块,通过module.exports导出了一个包含i18n属性的对象——这对应ES模块的默认导出,而非命名导出。而你在ES模块(.mjs文件)里用import { i18n }尝试做命名导入,自然会触发错误。

正确的导入与使用方式

方案1:默认导入后解构属性

修改next.config.mjs的导入逻辑,先导入整个默认导出的对象,再从中提取i18n:

import config from "./next-i18next.config.js";
const { i18n } = config;

const nextConfig = {
  reactStrictMode: false,
};

// .mjs属于ES模块,建议使用ES规范的导出语法
export default {
  i18n,
  ...nextConfig,
};

方案2:直接展开默认导出配置(简化写法)

如果不需要单独提取i18n,也可以直接展开整个配置对象:

import i18nConfig from "./next-i18next.config.js";

const nextConfig = {
  reactStrictMode: false,
};

export default {
  ...i18nConfig,
  ...nextConfig,
};

额外提示

.mjs文件遵循ES模块规范,推荐使用export default代替module.exports,保持语法一致性,避免混合模块规范带来的潜在问题。

内容的提问来源于stack exchange,提问作者riki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 22:07:11