R
Railway16mo ago
jins

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:
It looks like it deployed fine without dockerfile and without specifying prisma generate
Jump to solution
28 Replies
Percy
Percy16mo ago
Project ID: c915e2bf-b63f-4c12-b41e-131bdf5163fb
jins
jinsOP16mo ago
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
Brody
Brody16mo ago
can I see a screenshot of the service variables?
jins
jinsOP16mo ago
I am using a custom dockerfile too, which may be the issue? I just found this: https://docs.railway.app/deploy/dockerfiles
Brody
Brody16mo ago
depends, do you need any environment variables during the build phase?
jins
jinsOP16mo ago
not sure
Brody
Brody16mo ago
can you send your dockerfile please
jins
jinsOP16mo ago
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?
jins
jinsOP16mo ago
Brody
Brody16mo ago
can you modify your code? because it's most preferable to set the node version in your package.json with the engines.node field
jins
jinsOP16mo ago
Ya I already have this:
"engines": {
"node": ">=14.21.3",
"yarn": ">=1.22.0",
"npm": "please-use-yarn"
},
"engines": {
"node": ">=14.21.3",
"yarn": ">=1.22.0",
"npm": "please-use-yarn"
},
I working on updating so I can use Node 16 or 18, but for now I need to deploy with this version of 14
Brody
Brody16mo ago
then railway should pick up on that and use node 14 by default no worries
jins
jinsOP16mo ago
Okay, I will try this without the dockerfile
Brody
Brody16mo ago
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
jins
jinsOP16mo ago
I don't know what the at is for, I think it was specific to AWS. Someone else wrote the old dockerfile
Brody
Brody16mo ago
okay then try without any nixpacks.toml file then, and rename the dockerfile to something like Dockerfile.aws
jins
jinsOP16mo ago
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 still
Brody
Brody16mo ago
yes and that is why I offered to create a railway.json file to add the build step
jins
jinsOP16mo ago
If it's not too much hassle, that would be great so I can test both
Brody
Brody16mo ago
I will get to that when I'm back on my computer!
jins
jinsOP16mo ago
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
jins
jins16mo ago
It looks like it deployed fine without dockerfile and without specifying prisma generate
jins
jinsOP16mo ago
Although I have this defined in package.json
"engines": {
"node": ">=14.21.3",
"yarn": ">=1.22.0",
"npm": "please-use-yarn"
},
"engines": {
"node": ">=14.21.3",
"yarn": ">=1.22.0",
"npm": "please-use-yarn"
},
and deployment showed Nixpack installed Node v18:
╔══════════════ Nixpacks v1.11.0 ═════════════╗
║ setup │ nodejs-18_x, yarn-1_x, openssl ║
║─────────────────────────────────────────────║
║ install │ yarn install --frozen-lockfile ║
║─────────────────────────────────────────────║
║ build │ yarn run build ║
║─────────────────────────────────────────────║
║ start │ yarn run start ║
╚═════════════════════════════════════════════╝
╔══════════════ Nixpacks v1.11.0 ═════════════╗
║ setup │ nodejs-18_x, yarn-1_x, openssl ║
║─────────────────────────────────────────────║
║ install │ yarn install --frozen-lockfile ║
║─────────────────────────────────────────────║
║ build │ yarn run build ║
║─────────────────────────────────────────────║
║ start │ yarn run start ║
╚═════════════════════════════════════════════╝
Are only major versions valid for node engine for these deployments? https://nixpacks.com/docs/providers/node#setup
Brody
Brody16mo ago
correct
please-use-yarn
lol
jins
jinsOP16mo ago
lol okay thanks
Brody
Brody16mo ago
so all is good?
jins
jinsOP16mo ago
Yes I believe so. Thanks for your help today
Brody
Brody16mo ago
no problem 🙂
Want results from more Discord servers?
Add your server