Environment variables during built time?

imadtoubalHOBBY

3 months ago

I am trying to deploy a sveltekit app but I keep getting the following error:

```
error during build:

src/routes/papers/[id]/+page.server.ts (1:43): "PRIVATE_POCKETBASE_URL" is not exported by "virtual:env/static/private", imported by "src/routes/papers/[id]/+page.server.ts".

file: /app/src/routes/papers/[id]/+page.server.ts:1:43

1: import { PRIVATE_POCKETBASE_SERVICE_TOKEN, PRIVATE_POCKETBASE_URL } from '$env/static/private';

^

2: import type { PageServerLoad } from './$types';

at getRollupError (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:397:41)

at error (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:393:42)

at Module.error (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:16603:16)

at Module.traceVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:17052:29)

at ModuleScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:14709:39)

at ReturnValueScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)

at FunctionBodyScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:5582:38)

at Identifier.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:5356:40)

at TemplateLiteral.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:2779:28)

at CallExpression.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:2779:28)
```

I do have the environment variables set up for my app: https://snipboard.io/qZLmES.jpg

I followed: https://docs.railway.com/guides/sveltekit

Unsure what I am missing. I was using inline defined variables but now I need a private token to exist outside my repo.

Awaiting User Response

2 Replies

3 months ago

Hey there Imad,

For now, Railway doesn’t have the ability to offer variables at build time, unless you are sourcing them via ARG in a Dockerfile.

You will need to use a Dockerfile with your build if you want to pre-compile your pages with a variable.

(We have an experimental builder but that is unmaintained at the time.)

Best,

Angelo


Status changed to Awaiting User Response railway[bot] 3 months ago


3 months ago

The documentation for using variables at build time with a Dockerfile can be found here -

https://docs.railway.com/guides/dockerfiles#using-variables-at-build-time


Environment variables during built time? - Railway Help Station