Next.js Discord

Discord Forum

Next.js next.config.mjs file not behaving as expected

Unanswered
Pixiebob posted this in #help-forum
Open in Discord
PixiebobOP
I've been struggling with next.config.mjs file; I've tried the following and I got numerous errors with each way:

// next.config.mjs
import { defineConfig } from 'next';

export default defineConfig({
  reactStrictMode: true,
  output: 'standalone',
  images: {
    domains: ['example.com'], 
  },
  i18n: {
    locales: ['en-US', 'es'], // Supported locales for internationalization
    defaultLocale: 'en-US', // Default locale
  },
});


Import:
import { defineConfig } from 'next/config.js'; 


export default {
  reactStrictMode: true,
  output: 'standalone',
  images: {
    domains: ['example.com'],
  },
  i18n: {
    locales: ['en-US', 'es'],
    defaultLocale: 'en-US',
  },
};


but the following seemed to work:

import next from 'next';
const { defineConfig } = next;

export default next({
  reactStrictMode: true, // Enables React's strict mode for better debugging
  output: 'standalone', // Enables standalone output for better performance
  images: {
    domains: ['example.com'], // Specify allowed domains for image optimization
  },
  i18n: {
    locales: ['en-US', 'es'], // Supported locales for internationalization
    defaultLocale: 'en-US', // Default locale
  },
});


However, here is the .next folders contents after that, and as you can see, there is no .next/standalone folder.

root@web:/project-root/app/.next# ll
total 492
drwxr-xr-x 6 root root   4096 Sep 23 14:12 ./
drwxr-xr-x 9 root root   4096 Sep 23 15:09 ../
-rw-r--r-- 1 root root     21 Sep 23 14:12 BUILD_ID
-rw-r--r-- 1 root root   1005 Sep 23 14:11 app-build-manifest.json
-rw-r--r-- 1 root root     82 Sep 23 14:12 app-path-routes-manifest.json
-rw-r--r-- 1 root root    968 Sep 23 14:11 build-manifest.json
drwxr-xr-x 5 root root   4096 Sep 23 14:01 cache/
-rw-r--r-- 1 root root     94 Sep 23 14:12 export-marker.json
-rw-r--r-- 1 root root    511 Sep 23 14:12 images-manifest.json
-rw-r--r-- 1 root root   9439 Sep 23 14:12 next-minimal-server.js.nft.json
-rw-r--r-- 1 root root  64374 Sep 23 14:12 next-server.js.nft.json
-rw-r--r-- 1 root root     20 Sep 23 14:11 package.json
-rw-r--r-- 1 root root    959 Sep 23 14:12 prerender-manifest.json
-rw-r--r-- 1 root root      2 Sep 23 14:11 react-loadable-manifest.json
-rw-r--r-- 1 root root   4781 Sep 23 14:12 required-server-files.json
-rw-r--r-- 1 root root    831 Sep 23 14:11 routes-manifest.json
drwxr-xr-x 5 root root   4096 Sep 23 14:12 server/
drwxr-xr-x 5 root root   4096 Sep 23 14:11 static/
-rw-r--r-- 1 root root 350544 Sep 23 14:12 trace
drwxr-xr-x 3 root root   4096 Sep 23 14:11 types/


What am I doing wrong? Whats the correct way to set this option with Next.js 14

2 Replies

try

const nextConfig = {
reactStrictMode: true,
output: 'standalone',
images: {
domains: ['example.com'],
},
i18n: {
locales: ['en-US', 'es'],
defaultLocale: 'en-US',
},
}

module.exports = nextConfig;
file named next.config.js in my case