Utilizing internationalization and next/image in next.config.js alongside TypeScript

Currently, I am in the process of developing a miniature application using TypeScript within NextJS now that support for TypeScript comes standard in Next.js. Additionally, my aim is to integrate two recently introduced features:

Let's take a closer look at i18n:

// next.config.js
module.exports = {
    i18n: {
      // These are all the locales you want to support in
      // your application 
      // Sub-path Routing 
      locales: ['en', 'cn'],
      // This is the default locale you want to be used when visiting
      // a non-locale prefixed path e.g. `/hello`
      defaultLocale: 'en',
    },
  }

Unfortunately, incorporating these features into my next.config.js has proven quite challenging. While it functions as intended for regular applications (JavaScript only), I encounter the following error with the TypeScript version:

(node:15704) UnhandledPromiseRejectionWarning: TypeError: Cannot set property '__nextLocale' of undefined

If any of you have insights or can provide an example of how to effectively utilize next.config.js and integrate these new features into a TypeScript-based NextJS application, it would be greatly appreciated.

Answer №1

I believe there is no locale referred to as 'en' or 'cn'

https://en.wikipedia.org/wiki/Language_localisation

I suggest the following solution:

const withImages = require('next-images')
const withPWA = require('next-pwa')

module.exports = withPWA(
withImages({
  images: {
    domains: [
      'images.ctfassets.net',
      'imgix.cosmicjs.com',
	  'cdn.cosmicjs.com',
   ],
   i18n: {
      // List of supported locales in your application
      locales: ['en-US', 'zh-CN'],
      // Default locale when visiting a page without specifying a locale
      defaultLocale: 'pt-BR',
      ...
   }
 },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Angular application is not functioning properly after running npm start, even though all the necessary packages have

Encountering a perplexing issue with my Angular application. After checking out the code on my new machine, I attempted to run my existing Angular 12 project. However, despite the application running properly in the command prompt, it is not functioning as ...

Sorting through a JavaScript array

I am facing a peculiar problem while trying to filter an array in TypeScript. Here is the structure of my object: Sigma.model.ts export class Sigma { sigmaId: number; name: string; userId: number; starId: string; } `` The starId property contains com ...

When using HLS with Media Source Extensions on mobile devices, the <video> element with the muted and autoplay attributes may freeze on the first frame

I recently added a background video to our website using mux.com. The video is set to autoplay with HLS, but Chrome requires Media Source Extensions for playback. To ensure the HTML5 video auto plays, I included the necessary mute parameters as well. How ...

MaterialUI Divider is designed to dynamically adjust based on the screen size. It appears horizontally on small screens and vertically on

I am currently using a MaterialUI divider that is set to be vertical on md and large screens. However, I want it to switch to being horizontal on xs and sm screens: <Divider orientation="vertical" variant="middle" flexItem /> I h ...

Steps for referencing a custom JavaScript file instead of the default one:

Currently, I am utilizing webpack and typescript in my single page application in combination with the oidc-client npm package. The structure of the oidc-client package that I am working with is as follows: oidc-client.d.ts oidc-client.js oidc-client.rs ...

Encountering an Uncaught TypeError when attempting to set properties of null with useRef

I've been working on an app that requires access to the user's device camera in order to display live video on the screen. I've managed to achieve this by utilizing a video HTML Object and setting the media stream as its srcObject. Everythin ...

Verifying currency in mat-input field

I need help implementing validation for inputting prices on a form. For example, if a user types in $20.0000, I want a validation message to appear marking the input as invalid. Would this type of validation require regex, and if so, how would I go about ...

Latest version of NextJS (13.4.7) now includes improved functionality for dynamic routes, resulting in a more user

I am in the process of developing a NextJS 13.4.7 application that utilizes dynamic routes and a Headless CMS powered by Contentful. All routes are accessible, as shown in the screenshot below. Our goal is to fetch data from the CMS. If there is no data a ...

Step-by-step guide on how to index timestamp type using Knex.js

I'm in the process of indexing the created_at and updated_at columns using knex js. However, when I try to use the index() function, I encounter the following error: Property 'index' does not exist on type 'void' await knex.sche ...

What is the best way to update the value of a variable within a specific child component that is displayed using ngFor?

Hello there, I'm in need of some assistance with a coding issue. I have a parent component named "users-list" that displays a list of child components called "user" using *ngFor. Each component's class is dynamic and depends on various internal v ...

Obtaining AWS Cognito token using AWS Amplify's UI-React

I'm currently developing a Next.js frontend and NestJS backend application, and I am configuring the login component using the @aws-amplify/ui-react library. Following the steps outlined in the documentation here. import { Amplify } from 'aws-amp ...

Firebase data not appearing on screen despite using the async pipe for observables

My current challenge involves accessing data based on an id from Firebase, which comes back as an observable. Upon logging it to the console, I can confirm that the Observable is present. However, the issue arises when attempting to display this data on th ...

Navigating with Next.js router.push() changes the URL but fails to actually display the page

My Next.js app is running on localhost:3000 and it redirects to a login page if there is no user data. However, when it redirects to the login page, it doesn't render and I encounter this error: Error: Objects are not valid as a React child (found: [o ...

Nextjs throwing an error: createSVGPoint is not a valid function

I'm currently developing a simple game engine using Nextjs, React hooks, and SVG elements. One of the challenges I'm facing is detecting collisions between two SVG elements within the game. Initially, I tried using the syntax: circle.isPointInF ...

Using parameters and data type in Typescript

When I remove <IFirst extends {}, ISecond extends {}> from the declaration of this function, the compiler generates an error. Isn't the return value supposed to be the type after the double dot? What does <IFirst extends {}, ISecond extends { ...

Nextjs 13.4: GET request with parameters results in a 404 error

Hey, I'm having some trouble trying to send a fetch request with the parameter id to my API. The id is a string and I am using a dynamic route folder [...id] in the Link element. The Link Element <Link href={`/books/${id}`}">Book Number {i ...

Error: Unexpected token 'export' in NextJS Syntax

A situation has arisen where a library that was functioning perfectly in an app utilizing react-create-app is now needed for use in NextJS (using npx create-next-app --ts). However, upon attempting to integrate the library, an error was encountered: erro ...

One of the great features of Next.js is its ability to easily change

At the moment, my dynamic path is configured to display events by their ID [id].js localhost:3000/event/1 But I would like it to be structured as follows: localhost:3000/city/date/title. All of this information is available in the events database, but I&a ...

Creating a JSX.Element as a prop within a TypeScript interface

I need to create an interface for a component that will accept a JSX.Element as a prop. I have been using ReactNode for this purpose, but I am facing issues when trying to display the icon. How can I resolve this issue? export interface firstLevelMenuItem ...

What is the significance of default parameters in a JavaScript IIFE within a TypeScript module?

If I were to create a basic TypeScript module called test, it would appear as follows: module test { export class MyTest { name = "hello"; } } The resulting JavaScript generates an IIFE structured like this: var test; (function (test) { ...