-
Notifications
You must be signed in to change notification settings - Fork 0
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
NextJS support #99
Comments
Hey @JakeLo123, Thanks for this issue, I love it. Actually I've been struggling with this for quite some time during the past few days. A few comments:
And please lemme know when this issue is going to be addressed and what would be the workaround in the meantime. I have a reproducible repo for "document is not defined":
You can see error messages in the terminal, I am not sure but my best bet is this part since it is not able to prerender shop page even though it is a simple page like this. Error message: $ nx build:local frontend
> nx run frontend:"build:local"
> NODE_ENV=production nx build frontend
NX Running target build for project frontend and 1 task it depends on:
> nx run @shared:build
Compiling TypeScript files for project "@shared"...
Done compiling TypeScript files for project "@shared".
> nx run frontend:build
> next build
▲ Next.js 14.2.3
- Experiments (use with caution):
· outputFileTracingRoot
Creating an optimized production build ...
✓ Compiled successfully
Skipping linting
Checking validity of types ...
Collecting page data ...
Generating static pages (0/6) ...
Generating static pages (1/6)
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571) {
digest: '831143466'
}
Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571)
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571) {
digest: '831143466'
}
Error occurred prerendering page "/shop". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571)
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571) {
digest: '831143466'
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571)
Generating static pages (2/6)
Generating static pages (4/6)
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571) {
digest: '831143466'
}
Error occurred prerendering page "/sign-up". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26284
at get at_exp (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26404)
at c.scheduleTokenExpiration (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26526)
at new c (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:24884)
at /home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26974
at Object.nr [as useMemo] (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39130)
at t.useMemo (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109856)
at d (/home/kasir/projects/you-say/apps/frontend/.next/server/chunks/657.js:142:26969)
at nj (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46251)
at nM (/home/kasir/projects/you-say/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47571)
✓ Generating static pages (6/6)
> Export encountered errors on following paths:
/_not-found/page: /_not-found
/page: /
/shop/page: /shop
/sign-up/page: /sign-up
Warning: command "next build" exited with non-zero status code
NX Running target build for project frontend and 1 task it depends on failed
Failed tasks:
- frontend:build
Hint: run the command with --verbose for more details.
Warning: command "NODE_ENV=production nx build frontend" exited with non-zero status code
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Ran target build:local for project frontend (18s)
✖ 1/1 failed
✔ 0/1 succeeded [0 read from cache] |
I downgraded my -"@fusionauth/react-sdk": "^2.1.1",
+"@fusionauth/react-sdk": "^1.0.6" |
This issue board will reflect the status of the issue. We're working on a fix for this one 👍 |
NextJS support
Problem
If you are using the React SDK with NextJS, you must use the
"use client"
directive. This is not ideal for NextJS users.Solution
A solution is implemented for the Vue SDK/Nuxt #98 -- let's get the React SDK to parity.
Nextjs instructs users to use the
use client
directive when consuming 3rd party providers, so we should not have to make any changes due to our use ofReact.createContext
. Although we should include Next configuration in our docs--perhaps reference this article authored by Vercel.Alternatives/workarounds
Continue requiring Next users to use client side rendering.
Community guidelines
All issues filed in this repository must abide by the FusionAuth community guidelines.
How to vote
Please give us a thumbs up or thumbs down as a reaction to help us prioritize this feature. Feel free to comment if you have a particular need or comment on how this feature should work.
The text was updated successfully, but these errors were encountered: