nickchen120235
nickchen1202355mo ago

How to use private remote modules hosted on GitHub on Deno Deploy?

According to Private Modules and Repositories, I can access a private GitHub repo using the DENO_AUTH_TOKENS environment variable. How do I achieve this on Deno Deploy? I've tried setting DENO_AUTH_TOKEN on my project's settings page but it suggests that DENO_ is a reserved prefix.
No description
3 Replies
Deno AI Helper
Deno AI Helper5mo ago
To use private GitHub repositories as dependencies in Deno Deploy, you'll need to authenticate access to these private modules using the DENO_AUTH_TOKENS environment variable. However, since Deno Deploy reserves environment variables starting with DENO_, you cannot directly set DENO_AUTH_TOKENS in the Deno Deploy dashboard. Here's a workaround you can use: 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 general advice and not a direct code example from the documentation):
const ghAuthToken = Deno.env.get("GH_AUTH_TOKENS");
if (ghAuthToken) {
Deno.env.set("DENO_AUTH_TOKENS", ghAuthToken);
}

// Now you can import your private modules as usual
import { myPrivateDinoModule } from "https://raw.githubusercontent.com/user/repo/branch/mod.ts";
const ghAuthToken = Deno.env.get("GH_AUTH_TOKENS");
if (ghAuthToken) {
Deno.env.set("DENO_AUTH_TOKENS", ghAuthToken);
}

// Now you can import your private modules as usual
import { myPrivateDinoModule } from "https://raw.githubusercontent.com/user/repo/branch/mod.ts";
Make sure to replace the placeholders with your actual GitHub token, user, repository, branch, and module path. Remember, this is a general approach and you should ensure that your token is kept secure and not exposed in your code. 🦕
nickchen120235
nickchen1202355mo ago
No description
nickchen120235
nickchen1202355mo ago
I think it fails during caching when deploying? This is how I import my module in my code
import { load } from 'dotenv'

await load({ export: true })
const GH_AUTH_TOKEN = Deno.env.get('GH_AUTH_TOKEN')
if (GH_AUTH_TOKEN)
Deno.env.set('DENO_AUTH_TOKENS', GH_AUTH_TOKEN)

export {
MyClass1
} from 'https://raw.githubusercontent.com/path/to/module.ts'
import { load } from 'dotenv'

await load({ export: true })
const GH_AUTH_TOKEN = Deno.env.get('GH_AUTH_TOKEN')
if (GH_AUTH_TOKEN)
Deno.env.set('DENO_AUTH_TOKENS', GH_AUTH_TOKEN)

export {
MyClass1
} from 'https://raw.githubusercontent.com/path/to/module.ts'
Can confirm caching does not work if the environment variable is not set
$ deno cache --reload ./utils/module.ts
error: Module not found "https://raw.githubusercontent.com/path/to/module.ts".
at file:///home/me/my-project/utils/module.ts:23:8
$ deno cache --reload ./utils/module.ts
error: Module not found "https://raw.githubusercontent.com/path/to/module.ts".
at file:///home/me/my-project/utils/module.ts:23:8