question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore GSSP on next export

See original GitHub issue

Feature request

I expected next export to exclude any pages featuring GSSP. The desire is to use next’s built-in method to hoist all static content to a particular folder.

Is your feature request related to a problem? Please describe.

I am re-working the Firebase examples and want to leverage the Firebase CDN in a better way. Firebase Hosting priority order can be used to have all static resources on Firebase Hosting served first by the CDN and any request misses be fulfilled by the Cloud Functions hosted Next.js app. This requires me to run next export (I want to avoid duplicating this functionality myself) to produce the static resources to push to the CDN.

However, with SSG, the page is computed by the backend a single time if missing. I desire some pages to be SSR with GSSP.

Describe the solution you’d like

I would like a flag for next export to override the existing behavior which errors with:

Error occurred prerendering page "/index". Read more: https://err.sh/next.js/prerender-error:
Error: Error for page /index: pages with `getServerSideProps` can not be exported. See more info here: https://err.sh/next.js/gssp-export

For example: next export --ignore-gssp which performs as it does today, but skips pages with GSSP.

Describe alternatives you’ve considered

Using SSG mode with an empty paths paths:[], fallback:true works with next export and forces all content to be computed on request (doesn’t generate any build time .html or .json), but only once. This method also only works for dynamic routes /posts/[id].js. Not quite the behavior I want.

Using SSG mode with a per-page CDN cache flush is also a possibility, though highly dependent on the Hosting service. Firebase for instance, does not have any CDN cache flush or cache control outside of s-maxage. CDN cache flushing would also require tracking of BUILD_ID as it is used in the path for the .json data.

Using SSR mode with a large s-maxage & CDN cache flush is also possible, again, dependent on Hosting service and it’s availability of cache flushing.

I have considered:

  1. creating my own copy command to perform the hoist of static resources. From the source I can see:

    1. (copy static folder)
    .next/static                         -> out/_next/static
    
    2. (copy SSG .html files (without route regex in name))
    .next/server/static/{build_id}/pages -> out/
    
    3. (copy SSG .json data files)
    .next/server/static/{build_id}/pages -> out/_next/data/{build_id}
    
    4. (copy public folder)
    public                               -> out/
    

    This way I wouldn’t need to use next export, dynamic-route SSG pages would be computed on first request and SSR pages on each request 🤔

Additional context

  • next 9.3.5

For those finding this, I have created an example script: https://gist.github.com/jthegedus/8e820d37e1f3768f991886fb65de154f

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jthegeduscommented, May 26, 2020

We’re not planning to lift this restriction from next export given that most users running it would expect getServerSideProps to “just work” then and it does not when you’re doing a fully static export.

A flag for this command like next export --ignore-gssp wouldn’t change this for existing users.

next build already outputs static html for static pages and for what you’re trying to achieve you’ll have to build on top of that (similarly to how @vercel/next does it)

Other Hosting platforms would be able to utilise this for Next.js support without having to worry about any internal changes to the build output.

0reactions
balazsorban44commented, Jan 28, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gssp-export - Next.js
You attempted to statically export your application via next export , however, one or more of your pages uses getServerSideProps .
Read more >
Pages with `getServerSideProps` can not be exported
You can't use server-side rendering ( getServerSideProps ) when statically exporting a Next.js app with next export . See nextjs.org/docs/ ...
Read more >
Dynamic path with «next export»? : r/nextjs - Reddit
So I want to statically export something like post/[id].js, ... This is exactly what next.js does when you don't have gSSP or gSP....
Read more >
Advanced Practices for Nest.js + Next.js Projects
NEXT.js and nest.js are very similar in naming so I will be always ... export type GetServerSidePropsContext<Q = ParsedUrlQuery> = Omit< ...
Read more >
next-export-i18n - npm
Internationalize next.js with true support for next export. Latest version: 2.1.0, last published: 2 months ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found