Hi I’m building a turborepo app with some file generation apps
inside it. Regardless of whether or not I am doing this right (in regards to whether I should be using apps
to generate files, usually for other packages
), I have some doubts regarding environment variables. One of my apps (gen-gi-helper-data
) scrapes data from a google sheet, so I’d normally use a credentials.json
file to handle that, however, since Vercel doesn’t support that I’ve resorted to using environment variables to hold the fields of my credentials.json
. However I didn’t really make an .env
file anywhere and just changed the code to use process.env
instead like so:
credentials: {
type: process.env.GOOGLEAPIS_TYPE,
project_id: process.env.GOOGLEAPIS_PROJECT_ID,
private_key_id: process.env.GOOGLEAPIS_PRIVATE_KEY_ID,
private_key: process.env.GOOGLEAPIS_PRIVATE_KEY,
client_email: process.env.GOOGLEAPIS_CLIENT_EMAIL,
client_id: process.env.GOOGLEAPIS_CLIENT_ID,
// @ts-ignore
auth_uri: process.env.GOOGLEAPIS_AUTH_URI,
token_uri: process.env.GOOGLEAPIS_TOKEN_URI,
auth_provider_x509_cert_url:
process.env.GOOGLEAPIS_AUTH_PROVIDER_X509_CERT_URL,
client_x509_cert_url: process.env.GOOGLEAPIS_CLIENT_X509_CERT_URL,
}
The @ts-ignore
is because the other fields aren’t recognized by googleapis
, though just storing this all in a separate object fixes that.
Just changing my code to do this without testing it locally made it work in Vercel (with env variables), however adding a root .env
file in my local repo doesn’t work. I’m assuming I’m doing something wrong.
Moreover the docs recommend using .env
files per package, trying that doesn’t work either.
When I successfully deployed to Vercel, I got the following warning:
Warning - the following environment variables are set on your Vercel project, but missing from "turbo.json". These variables WILL NOT be available to your application and may cause your build to fail. Learn more at https://turbo.build/repo/docs/platform-environment-variables
[warn] @repo/gi-helper-data#build
[warn] - GOOGLEAPIS_TYPE
[warn] - GOOGLEAPIS_PROJECT_ID
[warn] - GOOGLEAPIS_PRIVATE_KEY_ID
[warn] - GOOGLEAPIS_PRIVATE_KEY
[warn] - GOOGLEAPIS_CLIENT_EMAIL
[warn] - GOOGLEAPIS_CLIENT_ID
[warn] - GOOGLEAPIS_AUTH_URI
[warn] - GOOGLEAPIS_TOKEN_URI
[warn] - GOOGLEAPIS_AUTH_PROVIDER_X509_CERT_URL
[warn] - GOOGLEAPIS_CLIENT_X509_CERT_URL
[warn] @repo/unity-richtext-react#build
[warn] - GOOGLEAPIS_TYPE
[warn] - GOOGLEAPIS_PROJECT_ID
[warn] - GOOGLEAPIS_PRIVATE_KEY_ID
[warn] - GOOGLEAPIS_PRIVATE_KEY
[warn] - GOOGLEAPIS_CLIENT_EMAIL
[warn] - GOOGLEAPIS_CLIENT_ID
[warn] - GOOGLEAPIS_AUTH_URI
[warn] - GOOGLEAPIS_TOKEN_URI
[warn] - GOOGLEAPIS_AUTH_PROVIDER_X509_CERT_URL
So I tried adding the following turbo.json
to the gen-gi-helper-data
app:
// apps/gen-gi-helper-data/turbo.json
{
"extends": ["//"],
"tasks": {
"generate": {
"env": [
"GOOGLEAPIS_TYPE",
"GOOGLEAPIS_PROJECT_ID",
"GOOGLEAPIS_PRIVATE_KEY_ID",
"GOOGLEAPIS_PRIVATE_KEY",
"GOOGLEAPIS_CLIENT_EMAIL",
"GOOGLEAPIS_CLIENT_ID",
"GOOGLEAPIS_AUTH_URI",
"GOOGLEAPIS_TOKEN_URI",
"GOOGLEAPIS_AUTH_PROVIDER_X509_CERT_URL",
"GOOGLEAPIS_CLIENT_X509_CERT_URL"
]
}
}
}
I previously only used pnpm --filter gen-gi-helper-data run generate
instead of turbo ...
, but adding this and using the appropriate turbo
equivalent doesn’t work either.
One more question I have is that .env
files are encouraged to be on a per-package/app basis, however Vercel only has a field for what I assume is root level environment variables. So how would I tell Vercel to pass some environment variables to certain packages/apps?