Trying to deploy a project on Deno Deploy with a private Github repository dependency
By reading the docs at https://docs.deno.com/runtime/manual/basics/modules/private I found that I can have a environment variable called DENO_DEPLOYTOKENS. This works perfectly locally and in Github Actions but in Deno Deploy I can't create environment variables starting with DENO, it's reserved. Any ideas? Thank you.
Private Modules and Repositories | Deno Docs
There may be instances where you want to load a remote module that is located in
3 Replies
It seems like you've encountered a common issue when trying to use private GitHub repositories as dependencies in Deno Deploy. The documentation does mention that you should use the
DENO_AUTH_TOKENS
environment variable to authenticate access to private modules. However, as you've noticed, Deno Deploy reserves environment variables starting with DENO_
, which means you can't directly set DENO_AUTH_TOKENS
in the Deno Deploy dashboard.
To work around this, you can use a different environment variable name to store your GitHub token and then pass it to the DENO_AUTH_TOKENS
variable at runtime within your code. Here's a general approach you can take:
1. Create an environment variable in the Deno Deploy dashboard with a different name, such as GH_AUTH_TOKENS
.
2. In your code, before you import any private modules, set the DENO_AUTH_TOKENS
environment variable using the value from GH_AUTH_TOKENS
. You can do this by accessing the environment variables using Deno.env.get("GH_AUTH_TOKENS")
and then setting DENO_AUTH_TOKENS
accordingly.
Here's a small code snippet to illustrate this:
Please note that this is a general advice and not a direct code example from the documentation. Make sure to replace the placeholders with your actual GitHub token, user, repository, branch, and modulepath.
Remember to keep your tokens secure and never expose them in your source code. Always use environment variables to handle sensitive data like authentication tokens. 🦕
thanks!