I’m trying to deploy my app on digitalocean and i’m have couple env variables im trying to use. I have added them in the settings of my app to the App-Level Environment Variables. However during build i see:
[2024-08-22 16:00:24] │ ✓ 203 modules transformed.
[2024-08-22 16:00:24] │ x Build failed in 1.68s
[2024-08-22 16:00:24] │ error during build:
[2024-08-22 16:00:24] │ src/lib/meilisearch/index.ts (1:30): "MEILISEARCH_HOST" is not exported by "virtual:$env/static/private", imported by "src/lib/meilisearch/index.ts".
[2024-08-22 16:00:24] │ file: /app/src/lib/meilisearch/index.ts:1:30
[2024-08-22 16:00:24] │
[2024-08-22 16:00:24] │ 1: import { MEILISEARCH_API_KEY, MEILISEARCH_HOST } from "$env/static/private";
[2024-08-22 16:00:24] │ ^
[2024-08-22 16:00:24] │ 2: import { Meilisearch } from "meilisearch";
[2024-08-22 16:00:24] │
[2024-08-22 16:00:24] │ at getRollupError (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:392:41)
[2024-08-22 16:00:24] │ at error (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:388:42)
[2024-08-22 16:00:24] │ at Module.error (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:13958:16)
[2024-08-22 16:00:24] │ at Module.traceVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:14406:29)
[2024-08-22 16:00:24] │ at ModuleScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:12110:39)
[2024-08-22 16:00:24] │ at Identifier.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:6941:40)
[2024-08-22 16:00:24] │ at Property.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:4808:23)
[2024-08-22 16:00:24] │ at ObjectExpression.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:4804:28)
[2024-08-22 16:00:24] │ at NewExpression.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:4804:28)
[2024-08-22 16:00:24] │ at VariableDeclarator.bind (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:4808:23)
[2024-08-22 16:00:24] │ error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1
[2024-08-22 16:00:24] │
[2024-08-22 16:00:24] │ command exited with code 1
[2024-08-22 16:00:24] │
[2024-08-22 16:00:24] │ ✘ build failed
i tried modyfing my dockerfile by adding:
ENV MEILISEARCH_API_KEY=$MEILISEARCH_API_KEY ENV MEILISEARCH_HOST=$MEILISEARCH_HOST …
etc.
however that doesn’t work, i also tried to define those as ARG to have them accessible during build but no luck there either.
Can someone help me?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
I think that when using SvelteKit with Vite, environment variables used during the build need to be prefixed with
VITE_
if they are to be accessible in the client-side code.Here’s what you can do:
Instead of using
MEILISEARCH_API_KEY
andMEILISEARCH_HOST
, rename them toVITE_MEILISEARCH_API_KEY
andVITE_MEILISEARCH_HOST
in your DigitalOcean App Platform settings.In your code, import these variables using
import.meta.env.VITE_MEILISEARCH_API_KEY
andimport.meta.env.VITE_MEILISEARCH_HOST
.Also as a side note, to pass environment variables to a Dockerfile-based resource, define them as build-time or run-time environment variables in App Platform. This passes variables down to the
docker build
process (with a--build-arg
parameter) anddocker run
process (with an-e
parameter) when App Platform builds and deploys your container. You can then access the values of the environment variables using theARG
keyword in your Dockerfile as you normally would.Let me know how it goes.
- Bobby