timlrx / tailwind-nextjs-starter-blog

This is a Next.js, Tailwind CSS blogging starter template. Comes out of the box configured with the latest technologies to make technical writing a breeze. Easily configurable and customizable. Perfect as a replacement to existing Jekyll and Hugo individual blogs.
https://tailwind-nextjs-starter-blog.vercel.app/
MIT License
8.83k stars 2.05k forks source link

Static Generation Build Error Following Instructions on README #744

Closed greynewell closed 9 months ago

greynewell commented 1 year ago

Describe the bug I am unable to generate static pages following the instructions in the README.

To Reproduce Steps to reproduce the behavior (taken from the README):

  1. Add output: 'export' in next.config.js. See static exports documentation for more information.

  2. Comment out headers() from next.config.js.

  3. Change components/Image.tsx to use a standard <img> tag instead of next/image:

    /* eslint-disable jsx-a11y/alt-text */
    /* eslint-disable @next/next/no-img-element */
    import NextImage, { ImageProps } from 'next/image'
    
    // @ts-ignore
    const Image = ({ ...rest }: ImageProps) => <img {...rest} />
    
    export default Image

    Alternatively, to continue using next/image, you can use an alternative image optimization provider such as Imgix, Cloudinary or Akamai. See image optimization documentation for more details.

  4. Remove api folder and components which call the server-side function such as the Newsletter component. Not technically required and the site will build successfully, but the APIs cannot be used as they are server-side functions.

  5. Run yarn build. You will receive the following error:

    > Build error occurred
    Error: Page "/tags/[tag]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.
    at /Users/grey/Projects/greynewell.com/node_modules/next/src/build/index.ts:1613:37
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Span.traceAsyncFn (/Users/grey/Projects/greynewell.com/node_modules/next/src/trace/trace.ts:110:14)
    at async Promise.all (index 11)
    at /Users/grey/Projects/greynewell.com/node_modules/next/src/build/index.ts:1427:9
    at Span.traceAsyncFn (/Users/grey/Projects/greynewell.com/node_modules/next/src/trace/trace.ts:110:14)
    at /Users/grey/Projects/greynewell.com/node_modules/next/src/build/index.ts:1322:11
    at Span.traceAsyncFn (/Users/grey/Projects/greynewell.com/node_modules/next/src/trace/trace.ts:110:14)
    at build (/Users/grey/Projects/greynewell.com/node_modules/next/src/build/index.ts:361:25)
    at main (/Users/grey/Projects/greynewell.com/node_modules/next/src/bin/next.ts:134:3)

    Expected behavior I expect yarn build to generate a static version of the blog.

System Info (if dev / build issue):

Additional context Add any other context about the problem here.

greynewell commented 1 year ago

You can see an example of this issue occurring here: https://github.com/greynewell/greynewell.com

Worth noting that (of course) generateStaticParams() is in fact defined.

Another user seems to have the same issue with next.js: https://github.com/vercel/next.js/issues/54393#issuecomment-1773808636

timlrx commented 1 year ago

Strange, I just tested it a month ago and it worked. Not sure if there was a bug introduced in the new version of next.

greynewell commented 1 year ago

@timlrx will give it another go with a fresh clone in the morning.

According to the comments on the Next issue I linked, error message was not displayed before, but the static files were not being generated. (I have not rolled back to test this assertion myself).

timlrx commented 11 months ago

@greynewell any further issues? Recently, I wrote up a guide on deploying it to Github pages and verified that the static build process works.

iamkroot commented 11 months ago

Managed to get it running (here) by following the guide, thanks @timlrx!

One thing though- the RSS feed is giving a 404 for some reason :( I do see the feed.xml file generated when I run yarn build locally and can access the file when I do a local serve, so not sure why the GH pages site is giving trouble.

hallucinogenizer commented 7 months ago

Anyone else still facing this issue? I've had to remove the tags route for now.

patrickstorm commented 4 months ago

For people seeing this in the future: I was running into this, and it was because I didn't have any posts with tags. I just added a tag to one of my posts, and the builds started passing.

greynewell commented 4 months ago

@patrickstorm would it add value to have a descriptive error message here?

patrickstorm commented 4 months ago

@patrickstorm would it add value to have a descriptive error message here?

@greynewell I suppose, but probably not worth the effort since it seems so few people run into this issue. And now if they find this github issue, they have a solution. I think the real fix would be to allow builds without any tags present.