Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!