Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
Env vars in Svelte - __myapp is not defined

I'm trying to set up env vars on my Svelte app to hide an API key.

I followed the instructions in this article [https://medium.com/dev-cafe/how-to-setup-env-variables-to-your-svelte-js-app-c1579430f032].

Here's the structure of my rollup.config.js

import { config as configDotenv } from 'dotenv';
import replace from '@rollup/plugin-replace';

configDotenv();

export default {
...
plugins: [
    replace({
        __myapp: JSON.stringify({
          env: {
            isProd: production,
            amplitude_api_key : process.env.amplitude_api_key
          } 
        })
      }),
]}

When I try to access the env var by calling: __myapp.env.API_KEY

I get this error: __myapp is not defined

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It seems that the nesting is the problem. I was able to get it work using this syntax:

replace({
  'process.env.isProd': production,
  'process.env.amplitude_api_key': process.env.amplitude_api_key
}),

and then use process.env.isProd in your app. Of course, if you like the __myapp thing, you could use __myapp instead of process on the left side of the replace function in your rollup config.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda