Search code examples
javascriptreactjsnext.jsreact-intl

Unable to find file path in getStaticProps function of internal page in Next Js


I am working on multi-language feature on Next JS app. Here is the folder structure of my project.

Folder Structure of the app

On the index page i.e. Home page, I am able to get the locales module using getStaticProps :

export function getStaticProps({ locale }) {
    return {
      props: {
        messages: require(`../locales/${locale}.json`),
      },
    };
}

But when I use this in /settings/locations/index/js it is showing error as follows: enter image description here

I have tried with messages: require('@/locales/${locale}.json') and messages: require('../../locales/${locale}.json') both way.


Solution

  • I think you should try with-

     return {
        props: {
          messages: require(`../../../locales/${locale}.json`),
        },
     };