Issues with Root Directory and NextJS deployment in Turbo repo
I have a turbo monorepo with a Next app I am trying to deploy. I need the paths for deployment to be as follows:
Deploy:
./apps/website
Build: ./
Install: ./
Variables: ./apps/website
Solution 1
- Set the Root Directory as ./
- Set the install phase cmd to npm install
(executes in ./
as desired)
- Set the buildCommand to npm run build
(executes in ./
as desired)
- Set the startCommand to npm run --prefix ./apps/website start
(executes in ./apps/website
as desired)
Problem: It attempts to load the ENV Variables at ./apps/website
when Railway thinks they are at ./
since thats what was specified as the Root Directory
Solution 2 (Ideal solution)
- Set the Root Directory as ./apps/website
- Set the install phase cmd to npm install --prefix ../..
- Set the buildCommand to npm run --prefix ../.. build
- Set the startCommand to npm run start
(executes in ./apps/website
as desired)
Problem: Railway seems to do some COPY . /app/.
process which makes any path outside the specified Root Directory inaccessible (ie ../../package.json
or the path ./package.json
in my monorepo does not exist) and therefore impossible to execute the install and build commands in the right path
Solution 2 is my idea situation since it scopes the deployment to the code that I want, this is how it works on Vercel.
I guess the two potential changes I would need are either:
- (ideal) Some way to change the directory at which Railway runs the COPY . /app/.
command to COPY ../.. /app/.
- Some way to change the path at which the ENV Variables are loadedSolution:Jump to solution
but your solution 1 would be the most applicable solution, with the exception that your install and build commands are filtered to only insall and build the apps/website app
12 Replies
Project ID:
6b3f7e42-b250-4b53-8639-abb14c79ab8b
6b3f7e42-b250-4b53-8639-abb14c79ab8b/service/91591431-792c-40cc-a0f2-16510cdd15e1
Problem: It attempts to load the ENV Variables at ./apps/website when Railway thinks they are at ./ since thats what was specified as the Root Directoryand
Some way to change the path at which the ENV Variables are loadedim not sure what these paths have to do with environment variables, could you please explain that?
Yeah so if I specify
./
as the Root Directory in the Railway dashboard its my assumption that Railway is attempting to load any Variables set in the dashboard at the path ./
. However, I am deploying from the path ./apps/website
which is likely why it cant find those variables?
This recent deployment fails because it cant load the ENV variables https://monorepo-production-610d.up.railway.app/maybe thats not how it works but for some reason it cant load the right vars
environment variables aren't scoped to anything
Ok, ill keep looking into it further thanks
id be happy to help, but theres not too much i can help with if theres no error messages
Solution
but your solution 1 would be the most applicable solution, with the exception that your install and build commands are filtered to only insall and build the apps/website app
Got it
Figured out the issue was I was using the wrong branch which had a slightly different name for one of the vars, my apologies. I appreciate your time.
no problem!