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

NX Monorepo配置next-translate报错:找不到i18n模块求助

在NX Monorepo中配置next-translate时遇到"找不到i18n模块"错误的解决求助

我正在尝试在NX Monorepo中配置next-translate,但遇到错误——找不到i18n模块。已在GitHub搜索相关方案,但提供的解决方法均无效,恳请帮忙解决。

技术栈

  • next 14.0.4
  • nx 18.2.2
  • next-translate 2.6.2
  • next-translate-plugin 2.6.2

错误信息

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Failed to process project graph.
  The "@nx/next/plugin" plugin threw an error while creating nodes from apps/web/next.config.js:
    Error: Cannot find module '/Users/sewnun/i18n'
    Require stack:
    - /Users/sewnun/Documents/repo/node_modules/next-translate-plugin/lib/cjs/index.js
    - /Users/sewnun/Documents/repo/apps/web/next.config.js
    - /Users/sewnun/Documents/repo/node_modules/@nx/next/src/plugins/plugin.js
    - /Users/sewnun/Documents/repo/node_modules/@nx/next/plugin.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/utils/nx-plugin.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/project-graph/build-project-graph.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/project-graph/project-graph.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/utils/project-graph-utils.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/daemon/server/file-watching/file-watcher-sockets.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/daemon/server/server.js
    - /Users/sewnun/Documents/repo/node_modules/nx/src/daemon/server/start.js
        at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
        at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/sewnun/Documents/repo/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
        at Function.Module._load (node:internal/modules/cjs/loader:985:27)
        at Module.require (node:internal/modules/cjs/loader:1235:19)
        at require (node:internal/helpers:176:18)
        at nextTranslate (/Users/sewnun/Documents/repo/node_modules/next-translate-plugin/lib/cjs/index.js:26:14)
        at combined (/Users/sewnun/Documents/repo/node_modules/@nx/next/src/utils/compose-plugins.js:10:36)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async getOutputs (/Users/sewnun/Documents/repo/node_modules/@nx/next/src/plugins/plugin.js:114:30)
        at async getBuildTargetConfig (/Users/sewnun/Documents/repo/node_modules/@nx/next/src/plugins/plugin.js:63:28)] {
  name: 'ProjectGraphError'
}

Node.js v21.1.0

Next配置文件(apps/web/next.config.js)

process.env.NEXT_TRANSLATE_PATH = '../..';

const { withNx, composePlugins } = require('@nx/next');
const withNextTranslate = require('next-translate-plugin');

const nextConfig = {
  nx: {
    svgr: false,
  },
};

const plugins = [withNx, withNextTranslate];
module.exports = composePlugins(...plugins)(nextConfig);

i18n.js文件

module.exports = {
  locales: ['ua', 'ru', 'en'],
  defaultLocale: 'ua',
  localeDetection: false,
  loader: false,
  pages: {
    '*': ['header', 'footer', 'common'],
    '/': ['header', 'footer'],
    // 其他页面配置
  },
  loadLocaleFrom: async (locale, namespace) =>
    import(`./locales/${locale}/${namespace}`).then((r) => r.default),
};

已尝试的解决方法

曾尝试直接使用next-translate/loader,虽避免了上述报错,但项目无法找到locales文件,页面仅显示翻译键,问题未得到解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 12:53:19