strapi / starters-and-templates

Monorepo for all official Strapi v4 templates
MIT License
327 stars 117 forks source link

Frontend setup fail #66

Open fatihcaliss opened 1 year ago

fatihcaliss commented 1 year ago

After command used: npx create-strapi-starter mysite3 next-corporate

Backend installed and run successfully but frontend did not. I'm getting this error: TypeError: Cannot destructure property 'metadata' of 'global.attributes' as it is undefined.

Anyone can help me with this issue? regards,

massweb58 commented 1 year ago

I tried with node 18 latest version and it works

fatihcaliss commented 1 year ago

Could you write exact node version? Is it 18.12.1?

robukh commented 1 year ago

Could you write exact node version? Is it 18.12.1?

Hello, I also got the same issue. My node version is 18.12.1.

edwardbattistini commented 1 year ago

I need help with this too

massweb58 commented 1 year ago

With the nextjs frontend regarding the strapi/next blog, you have to use node 16.14.0 and also use yarn (I use yarn 1.22.19).

salvatorericcardi commented 1 year ago

I'll wait a patch for strapi starter next-blog. This one doesn't work with node 18.12.1 and yarn .1.22.19. Tomorrow I'll try with node 16.14.0, are you sure it works with this version? @massweb58

massweb58 commented 1 year ago

Yes it works fine with nodejs 16.14.0. FYI, the blog with Gatsby and STrapi works with the latest version of nodejs 18.x.x

salvatorericcardi commented 1 year ago

I have just done... I confirm it works with node@16.14.0. Thanks @massweb58

webhype commented 1 year ago

Can't get next-corporate to work with Node 16.14.0 or any other node version. It's amazing that none of the starters, the front door for Strapi, the one thing that all new Strapi developers are encouraged to try, all completely fail. next-corporate with Javascript goes through the installer but fails at runtime. next-corporate with Typescript fails at install time. The only starter that works is next-blog.

staminna commented 1 year ago

MacOS 12.6.1 Now using node v16.14.0 (npm v8.3.1) me@localhost frontend % npm run develop

my-next-corporate@1.0.7 develop next

ready - started server on 0.0.0.0:3000, url: http://localhost:3000 info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5 event - compiled successfully event - build page: /[[...slug]] wait - compiling... event - compiled successfully event - build page: /next/dist/pages/_error wait - compiling... event - compiled successfully error - pages/_app.js (17:10) @ MyApp TypeError: Cannot destructure property 'metadata' of 'global.attributes' as it is undefined. 15 | } 16 |

17 | const { metadata, favicon, metaTitleSuffix } = global.attributes | ^ 18 | 19 | return ( 20 | <> TypeError: Cannot read properties of undefined (reading 'global') at getGlobalData (webpack-internal:///./utils/api.js:361:22) at processTicksAndRejections (node:internal/process/task_queues:96:5)

boogiebug commented 1 year ago

These are my fixes:

frontend/utils/api.js

export async function getGlobalData(locale) {
  ...
  const global = await globalRes.json()  
  // you may add this block if you wish to see the error message
  if ( global.errors ) {
    global.errors.forEach( e => console.log(e.message));
  }
  return global.data?.global.data; // <-- here
}

frontend/pages/_app.js

const MyApp = ({ Component, pageProps }) => {
  // Extract the data we need
  const { global } = pageProps

  // add following block! 
  if ( ! global ) {
    return <ErrorPage statusCode={404} />
  }
 ...

frontend/pages/[[...slug]].js

export async function getStaticProps(context) {
  ...
  return {
    props: {
      preview,
      sections: contentSections,
      metadata,
      global: globalLocale, // <-- here! remove .attributes
      pageContext: {
        ...pageContext,
        localizedPaths,
      },
    },
  }
}

Ensure that you have all 'Global' content created with all fields on the back-end.