-
Notifications
You must be signed in to change notification settings - Fork 396
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
next build failing with missing environment variables #1356
Comments
Hi @nickzelei - thanks for raising this Originally I thought this was an issue with Next.js trying to statically render an API route when it used a Dynamic function. But I see the SDK is trying to get config before Next.js can bail out of static rendering the route. I don't think this is going to get fixed on the Next.js end, so I'll leave this open to investigate a solution. In the meantime, you can use your workaround of providing dummy values to the build. |
+1 running into this. My builders are spread across different environments so ideally I'd like to avoid remembering to update the environments everywhere. Working around this right now by just having some default environment variables everywhere. Specifically impacting APIs using the App Router and nextjs-auth0 version - 3.0.1 |
Perhaps this bug is related to the following pull request (vercel/next.js#54203), which was fixed in version v13.4.19. |
I fixed this by calling export const GET = async (req, ctx) => {
const response = await handleAuth()(req, ctx);
return response;
}; You can avoid calling it each time by lazy storing it in scope: import { handleAuth, type AppRouteHandlerFn } from "@auth0/nextjs-auth0";
let _handleAuth: AppRouteHandlerFn | undefined;
export const GET: AppRouteHandlerFn = async (req, ctx) => {
if (typeof _handleAuth === "undefined") {
_handleAuth = handleAuth() as AppRouteHandlerFn;
}
const response = await _handleAuth(req, ctx);
return response;
}; |
It makes sense that lazy loading it will fix it as the environment variables won't be access until they need to be (which is how it should be imo 😄 ) - however, I'm not sure putting the |
These two are mutual: export const GET = x(); export const GET = (...args) => x()(...args); Except, of course, that the |
Yeah I'm running into this when pushing to Azure Static Web Apps as well... This seems ridiculous to check for a secret during CI... Implementing the fix from @g12i worked, Thanks!! |
still encounter the error My
|
@g12i's fix does fix the
|
Hi all 👋 - I've published an experimental tag that defers reading the configuration of the SDK until request time, which allows the SDK to instruct Next.js to bail out of static rendering before the config is read - full pr is #1541 (interesting bit is bec7d6c#diff-c3095d5010e65c52737a98a5d618ea24049ebe90c8470752426081d70ed6e012) @nickzelei - I've tested it on your repo and confirm that the project builds successfully without the I'd be grateful if a few other people who have requested this tried it out too and let me know if they experience any issues. You can test the experimental tag by installing the SDK like so |
hey @adamjmcgrath your changes seem to allow a build now. I reproduced by:
Awesome! |
@adamjmcgrath, thank you for resolving the previous issue. Retracting my comment as this thread is unrelated to my concern. |
Checklist
Description
I'm running
next build
against a fresh repo generated with the create next app and am running into build errors due to missing Auth0 environment variables.It seems that this is because I don't have a
.env.local
with the environment variables specified there.Why do I need this? These will be provided at runtime, so am confused as to why they are failing build steps.
I followed these two issues which seem to have fixed this, but I am not seeing that.
Reproduction
/app/api/auth/[auth0]/route.ts
file with the recommended setup.npm run build
You can skip the first two steps by cloning my repo here: https://github.com/nickzelei/auth0-bug
Running
npm run build
results in an error due to missing environment variables.This can be fixed by adding a basic
.env.local
fileAdditional context
No response
nextjs-auth0 version
3.1.0
Next.js version
13.4.13
Node.js version
18.16.0
The text was updated successfully, but these errors were encountered: