Shared variables not detected in Next.js app
Hi,
Does anyone know why two different Next.js apps I tried to deploy do not detect the shared variables shared to the environment being deployed?
I have two environments:
staging
and production
and I set shared variables in the project settings.
For each environment I pulled the shared variables to use as service variables.
Deployment kept failing because the env variables linked to the shared variables were undefined. If I explicitly set these with a value in the service variables instead of using shared, then it works.Solution:Jump to solution
It looks like it deployed fine without dockerfile and without specifying
prisma generate
28 Replies
Project ID:
c915e2bf-b63f-4c12-b41e-131bdf5163fb
c915e2bf-b63f-4c12-b41e-131bdf5163fb
Also, I just noticed once I stop using the shared variables, the build works now but all env variables on client and server are undefined in the deployed app.
This app works fine on AWS EC2 as-is and it also worked on Vercel when I tested it. Not sure why it's not reading the env variables on Railway now.
For example the image URLs are broken because it's not reading the variables:
https://undefined.s3.undefined.amazonaws.com/undefined/site-settings/fd72c104-7119-48b1-b632-cf67750d720b1641936544490.jpeg
can I see a screenshot of the service variables?
I am using a custom dockerfile too, which may be the issue? I just found this:
https://docs.railway.app/deploy/dockerfiles
depends, do you need any environment variables during the build phase?
not sure
can you send your dockerfile please
Thsi dockerfile was for AWS. I could delete but I need to use at least Node v14.21.3 for now.
Does
NIXPACKS_NODE_VERSION
set the latest release for a specified version?can you modify your code? because it's most preferable to set the node version in your package.json with the
engines.node
fieldYa I already have this:
I working on updating so I can use Node 16 or 18, but for now I need to deploy with this version of 14
then railway should pick up on that and use node 14 by default
no worries
Okay, I will try this without the dockerfile
would you be interested in trying out nixpacks?
you install an apt package and have a prisma generate build step, that will require a custom railway.json file
I can write that for you if you'd like
I don't know what the at is for, I think it was specific to AWS. Someone else wrote the old dockerfile
okay then try without any nixpacks.toml file then, and rename the dockerfile to something like Dockerfile.aws
I just deployed a test project with
railwayapp-templates/nextjs-prisma
and it doesn't look like it adds the prisma generate step. I thought it was required though for production stillyes and that is why I offered to create a railway.json file to add the build step
If it's not too much hassle, that would be great so I can test both
I will get to that when I'm back on my computer!
No problem, I'm going to eat lunch quick as well and try the deploy without dockerfile when I get back
thank you for your help
Solution
It looks like it deployed fine without dockerfile and without specifying
prisma generate
Although I have this defined in
package.json
and deployment showed Nixpack installed Node v18:
Are only major versions valid for node engine for these deployments?
https://nixpacks.com/docs/providers/node#setupcorrect
please-use-yarnlol
lol okay thanks
so all is good?
Yes I believe so. Thanks for your help today
no problem 🙂