1

I'm trying to add environment variables to a Svelte project. Tryied lots of solutions, including this but all I get is the error "Uncaught ReferenceError: __myapp is not defined"

1 Answer 1

1

The article appears to be outdated, the replace function has to contain something like this. Check the readme for plugin replace.

add this to the rollup.config.js


replace({
      values: {
        __myapp: JSON.stringify({
            isProd: production,
          ...config().parsed
        }),
      },
    }),

App.svelte file.

<script>
  console.log(__myapp);
  const { isProd, API_URL } = __myapp;
</script>

<h4>{isProd} - {API_URL}</h4>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.