Reputation: 11
Trying to configure next-translate with NX monorepo, but getting an error - module i18n is not found. Searched all the github, but given workarounds don't work. Could anyone help? My stack:
Error
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/modules/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 config
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', ],
<other pages>
},
loadLocaleFrom: async (locale, namespace) =>
import(`./locales/${locale}/${namespace}`).then((r) => r.default),
};
I tried following this repo https://github.com/amosbastian/nx-next-translate, using next-translate/loader directly, but this didn't result anything. Yes, I avoided error from firing, but locales were not found in the project, just translation keys were displayed
Upvotes: 1
Views: 231