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

Time:10-29

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.

CodePudding user response:

I think you should try with-

 return {
    props: {
      messages: require(`../../../locales/${locale}.json`),
    },
 };
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related