2 years ago

#62445

test-img

someone

NEXTJS error: export encountered error on following paths

I am using nextjs to query contentful. The posts are loading as are thee slugs during next dev however during npm run build i keept getting the error as mentioned in the title. I don't know why. I have attached the path in question as well as the build error log. I have also attached the repo so you can see the paths.

https://github.com/shar27/teaching-esl/tree/master/pages

it has a problem with this page route. What am I missing here?

import Link from 'next/link'
import Image from 'next/image'
import Nav from './Nav'
import Logo from './Logo'

export default function Allposts({ post }) {
  const { title, slug, thumbnail } = post.fields
console.log(post);
  return (
    
    
    <div className="card">
          <div className="featured">
        <Image 
          src={'https:' + thumbnail.fields.file.url}
          width={thumbnail.fields.file.details.image.width}
          height={thumbnail.fields.file.details.image.height}
        />
      </div>
      <div className="content">
        <div className="info">
          <h4>{ title }</h4>
          
        </div>
        <div className="actions">
          <Link href={'/Allposts/' + slug}><a>Read more</a></Link>
        </div>
      </div>
</div>
   

build error log

info  - Loaded env from C:\Users\Owner\teacher-esl\.env.local
info  - Checking validity of types  
info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
info  - Using external babel configuration from C:\Users\Owner\teacher-esl\.babelrc
info  - Creating an optimized production build  
warn  - Compiled with warnings

./node_modules/@mui/utils/esm/useId.js
Attempted import error: 'useId' is not exported from 'react' (imported as 'React').

Import trace for requested module:
./node_modules/@mui/utils/esm/index.js
./node_modules/@mui/material/utils/capitalize.js
./node_modules/@mui/material/utils/index.js
./node_modules/@mui/icons-material/utils/createSvgIcon.js
./node_modules/@mui/icons-material/Facebook.js
./pages/ContactPage.js

./node_modules/@mui/utils/esm/useId.js
Attempted import error: 'useId' is not exported from 'react' (imported as 'React').

Import trace for requested module:
./node_modules/@mui/utils/esm/index.js
./node_modules/@mui/material/utils/capitalize.js
./node_modules/@mui/material/utils/index.js
./node_modules/@mui/icons-material/utils/createSvgIcon.js
./node_modules/@mui/icons-material/Facebook.js
./pages/ContactPage.js

info  - Collecting page data  
[    ] info  - Generating static pages (0/36)undefined

Error occurred prerendering page "/components/Posts". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'fields')
    at Allposts (C:\Users\Owner\teacher-esl\.next\server\chunks\627.js:67:12)
    at d (C:\Users\Owner\teacher-esl\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:33:498)
    at bb (C:\Users\Owner\teacher-esl\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:36:16)
    at a.b.render (C:\Users\Owner\teacher-esl\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:42:43)
    at a.b.read (C:\Users\Owner\teacher-esl\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:41:83)
    at Object.exports.renderToString (C:\Users\Owner\teacher-esl\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:52:138)  
    at Object.renderPage (C:\Users\Owner\teacher-esl\node_modules\next\dist\server\render.js:673:46)
    at Object.defaultGetInitialProps (C:\Users\Owner\teacher-esl\node_modules\next\dist\server\render.js:315:51)
    at Function.getInitialProps (C:\Users\Owner\teacher-esl\.next\server\pages\_document.js:645:16)
    at Object.loadGetInitialProps (C:\Users\Owner\teacher-esl\node_modules\next\dist\shared\lib\utils.js:69:29)
undefined
[=   ] info  - Generating static pages (29/36)[
  {
    metadata: { tags: [] },
    sys: {
      space: [Object],
      id: '5AiKoR29E962N8mzOd0ZSi',
      type: 'Entry',
      createdAt: '2022-01-17T17:37:04.404Z',
      updatedAt: '2022-01-17T17:37:04.404Z',
      environment: [Object],
      revision: 1,
      contentType: [Object],
      locale: 'en-US'
    },
    fields: {
      title: 'Why the English learning system is broken.',
      slug: 'why-the-english-learning-system-is-broken',
      thumbnail: [Object],
      featuredImage: [Object],
      information: [Object]
    }
  },
  {
    metadata: { tags: [] },
    sys: {
      space: [Object],
      id: 'tUDkQ4pAfDglflH3RXyYc',
      type: 'Entry',
      createdAt: '2021-12-13T19:31:15.257Z',
      updatedAt: '2021-12-13T19:31:15.257Z',
      environment: [Object],
      revision: 1,
      contentType: [Object],
      locale: 'en-US'
    },
    fields: {
      title: 'How can I improve my English?',
      slug: 'how-can-i-improve-my-english',
      thumbnail: [Object],
      featuredImage: [Object],
      information: [Object]
    }
  },
  {
    metadata: { tags: [] },
    sys: {
      space: [Object],
      id: '2VazTl9F3FJqQPkR9WGcLF',
      type: 'Entry',
      createdAt: '2021-12-09T10:17:29.679Z',
      updatedAt: '2021-12-09T20:04:18.955Z',
      environment: [Object],
      revision: 2,
      contentType: [Object],
      locale: 'en-US'
    },
    fields: {
      title: 'How to learn English?',
      slug: 'how-to-learn-english',
      thumbnail: [Object],
      featuredImage: [Object],
      information: [Object]
    }
  }
]
{
  metadata: { tags: [] },
  sys: {
    space: { sys: [Object] },
    id: '5AiKoR29E962N8mzOd0ZSi',
    type: 'Entry',
    createdAt: '2022-01-17T17:37:04.404Z',
    updatedAt: '2022-01-17T17:37:04.404Z',
    environment: { sys: [Object] },
    revision: 1,
    contentType: { sys: [Object] },
    locale: 'en-US'
  },
  fields: {
    title: 'Why the English learning system is broken.',
    slug: 'why-the-english-learning-system-is-broken',
    thumbnail: { metadata: [Object], sys: [Object], fields: [Object] },
    featuredImage: { metadata: [Object], sys: [Object], fields: [Object] },
    information: { nodeType: 'document', data: {}, content: [Array] }
  }
}
{
  metadata: { tags: [] },
  sys: {
    space: { sys: [Object] },
    id: 'tUDkQ4pAfDglflH3RXyYc',
    type: 'Entry',
    createdAt: '2021-12-13T19:31:15.257Z',
    updatedAt: '2021-12-13T19:31:15.257Z',
    environment: { sys: [Object] },
    revision: 1,
    contentType: { sys: [Object] },
    locale: 'en-US'
  },
  fields: {
    title: 'How can I improve my English?',
    slug: 'how-can-i-improve-my-english',
    thumbnail: { metadata: [Object], sys: [Object], fields: [Object] },
    featuredImage: { metadata: [Object], sys: [Object], fields: [Object] },
    information: { nodeType: 'document', data: {}, content: [Array] }
  }
}
{
  metadata: { tags: [] },
  sys: {
    space: { sys: [Object] },
    id: '2VazTl9F3FJqQPkR9WGcLF',
    type: 'Entry',
    createdAt: '2021-12-09T10:17:29.679Z',
    updatedAt: '2021-12-09T20:04:18.955Z',
    environment: { sys: [Object] },
    revision: 2,
    contentType: { sys: [Object] },
    locale: 'en-US'
  },
  fields: {
    title: 'How to learn English?',
    slug: 'how-to-learn-english',
    thumbnail: { metadata: [Object], sys: [Object], fields: [Object] },
    featuredImage: { metadata: [Object], sys: [Object], fields: [Object] },
    information: { nodeType: 'document', data: {}, content: [Array] }
  }
}
info  - Generating static pages (36/36)

> Build error occurred
Error: Export encountered errors on following paths:
        /components/Posts
    at C:\Users\Owner\teacher-esl\node_modules\next\dist\export\index.js:493:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Span.traceAsyncFn (C:\Users\Owner\teacher-esl\node_modules\next\dist\trace\trace.js:74:20)
    at async C:\Users\Owner\teacher-esl\node_modules\next\dist\build\index.js:970:17
    at async Span.traceAsyncFn (C:\Users\Owner\teacher-esl\node_modules\next\dist\trace\trace.js:74:20)
    at async C:\Users\Owner\teacher-esl\node_modules\next\dist\build\index.js:844:13
    at async Span.traceAsyncFn (C:\Users\Owner\teacher-esl\node_modules\next\dist\trace\trace.js:74:20)
    at async Object.build [as default] (C:\Users\Owner\teacher-esl\node_modules\next\dist\build\index.js:82:25)

reactjs

next.js

environment-variables

contentful

0 Answers

Your Answer

Accepted video resources