sst: Parameter and Secrets not working / strange behavior (next.js 13 app)
Hi everyone,
i created a next.js app following this tutorial: https://sst.dev/examples/how-to-create-a-nextjs-app-with-serverless.html.
So we use the “drop in” approach for sst. We use the newest version of sst and next. Cleaned out any Stack and Bootstrap stuff in AWS.
In our Stack we added some Parameters and Secrets like so:
`const nextAuthSecret = new Config.Secret(stack, “NEXTAUTH_SECRET”);
const nextAuthUrl = new Config.Parameter(stack,"NEXTAUTH_URL",{
value: "http://localhost:3000"
})
const jwtMaxeAge = new Config.Parameter(stack,"JWT_MAX_AGE",{
value: "86400"
})
…
const site = new NextjsSite(stack, "ai-chat-stack", {
timeout: '30 seconds',
memorySize: '1 GB',
customDomain: {
domainName: "x.xyz.services",
hostedZone: "xyz.services"
},
bind: [
nextAuthSecret, nextAuthUrl,......
]
});`
We then populated the secret values with cli for local dev and prod environment. When we deploy the app and open the landing page of the app we always hit the same error: Some required environment variables are not set:
"This is usually the case when you are using an older version of SST. Please update SST to the latest version to use the SST Config feature."
I thought they are being populated automatically? This also happens with any secret and parameter, so not related to next-auth… and we use the newest version of sst
best
Thomas
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 20 (9 by maintainers)
since nothing happend for almost three months, we moved away from sst.
sorry we don’t use discord in our company, anyway i’m not looking for support. The example from the docs is not working and secrets and parameters seem not to work with next.js app. So this is a bug report…
Project to verfiy: project-to-reproduce.zip
Steps: 1.) created next app 2.) create sst app in root folder of next app 3.) add parameter to stack 5.) add parameter to stack as next js public variable 6.) created a controller and try to access parameter with Config.XYZ -> not working 7.) create a frontendpage and try to access next js public var -> working, but i also can access the non public variable in the frontend page now which is strange
I’m seeing errors with this also. I followed Next + SST setup tutorial, and then the Parameters/Secrets tutorial.
yarn dev, I getCannot use Config.MY_ENV_VAR. Please make sure it is bound to this function.when trying to load a server-side page that uses aParameterin a browser.yarn build, I getType error: Property 'MY_ENV_VAR' does not exist on type 'ConfigTypes & ParameterTypes & SecretTypes'.on the same page during the build, in the console output.Create a new app:
yarn create next-app- select all defaultscd my-appyarn create sstdrop-in: truewhen promptedyarn installyarn devParameterfollowing this: https://docs.sst.dev/configCannot use Config.MY_ENV_VAR. Please make sure it is bound to this function.I made a repo here that reproduces: https://github.com/sennett/sst-env-vars-cannot-use
nvm useyarn installyarn devUnhandled Runtime ErrorError: Cannot use Config.MY_ENV_VAR. Please make sure it is bound to this function.yarn buildType error: Property 'MY_ENV_VAR' does not exist on type 'ConfigTypes & ParameterTypes & SecretTypes'.sst bind next buildCheers.
EDIT:
I tried this all the way back to v2.11.14 and it gave the same error every time. Does anyone have any ideas?