Hafiz Abdullah Tahir
Hafiz Abdullah Tahir

Reputation: 21

Unable to use output: 'export' in next config file with i18n locales | Next JS

Question: Handling Next.js output: export and i18n Conflict During Build

I am facing an issue with next export and output: export configuration in Next.js. Since next export has been deprecated in favor of output: export, I followed suggestions to update my next.config.js file. However, I encountered multiple errors after making the changes.

Problem Description:

When I run yarn export, I get the following error:

Error: Specified "i18n" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-i18n

I read online that next export and output: export are incompatible with i18n locales, but I can't remove my locale configuration as it would cause several issues in my project. Removing the i18n configuration leads to numerous other errors, which are difficult to manage without potentially regenerating all pages.

Current Configuration:

next.config.js

module.exports = {
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: [`@svgr/webpack`],
    });
    return config;
  },
  i18n: {
    locales: ['en', 'de', 'ar'],
    defaultLocale: 'en',
    localeDetection: false,
  },
  images: {
    unoptimized: true,
    domains: ['your-domain.com'],
  },
  experimental: {
    isrMemoryCacheSize: 0,
    workerThreads: true,
    cpus: Math.max(1, require('os').cpus().length / 2),
  },
};

package.json Scripts

"scripts": {
  "dev": "next",
  "build": "next build",
  "start": "next start",
  "export": "next build && next export",
  "static": "next build",
  "serve": "npx serve out",
  "type-check": "tsc",
  "lint": "eslint --ignore-path .gitignore \"src/**/*.+(ts|js|tsx)\"",
  "format": "prettier --ignore-path .gitignore \"src/**/*.+(ts|js|tsx)\" --write",
  "postinstall": "husky install"
}

Issue Summary:

What I've Tried:

  1. I’ve added output: 'export' to next.config.js as suggested by Next.js documentation.
  2. I tried removing i18n locales, but this led to various other errors.
  3. I also reviewed the official Next.js documentation and error messages but couldn’t find a solution that allows using output: export and i18n together.

Questions:

Any help or guidance would be highly appreciated!

Upvotes: 2

Views: 86

Answers (0)

Related Questions