1

I am trying Commerce js with NextJS in the commerce.js file everything works well and I have all the return data. But when I import the data from commerce.js file getStaticProps return undefine

import { client } from '../utils/commerce'

const getStaticProps = async () => {
  const commerce = client
    const { data } = await commerce.products.list()

    return {
        props: {
            products: data
        }
    }
}

export default function Home({ products }) {
  
    console.log(products)

    return (
        <> <div> Hello </div> </>
    ) 
}

The console.log(products) return undefine Can someone help me understand the problem, please?

Commerce.js file

import Commerce from '@chec/commerce.js'

export const client = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_API_KEY, true)
fyardlest
  • 288
  • 4
  • 17
  • 1
    can you provide some code from your commerce file please? So I can see how the imported {client} is structured – Andrew Ross May 08 '21 at 04:57
  • Hi Andrew, I just have the following code in the commerce.js file: import Commerce from '@chec/commerce.js' export const client = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_API_KEY, true) – fyardlest May 08 '21 at 16:25

1 Answers1

0

Sometimes I ask myself why we have to make mistakes while coding, LOL! Gyus I just forget to export the getStaticProps method. It is nonsense, really.

fyardlest
  • 288
  • 4
  • 17