Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda