Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend setup fail #66

Open
fatihcaliss opened this issue Nov 24, 2022 · 11 comments
Open

Frontend setup fail #66

fatihcaliss opened this issue Nov 24, 2022 · 11 comments

Comments

@fatihcaliss
Copy link

fatihcaliss commented Nov 24, 2022

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.

  • node : 16.15.0 (I also tried Node version 14.21.0)
  • npm : 8.5.5

Anyone can help me with this issue?
regards,

@massweb58
Copy link

I tried with node 18 latest version and it works

@fatihcaliss
Copy link
Author

Could you write exact node version? Is it 18.12.1?

@robukh
Copy link

robukh commented Nov 29, 2022

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
Copy link

I need help with this too

@massweb58
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@webhype
Copy link

webhype commented Jan 2, 2023

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants