New values not being loaded for .env for SvelteKit app

31 Views Asked by At

I am unable to get Sveltekit to read the latest values from .env.

Any help on where are these old values coming from?

I have tried the following ways:

1.

import { SALESFORCE_CLIENT_SECRET, SALESFORCE_CLIENT_ID, SALESFORCE_CALLBACK_URI_BASE } from '$env/static/private'
import { env } from '$env/dynamic/private'
console.log('meta.env.DEV-->', import.meta.env.DEV.valueOf());
console.log('settings-static-->', SALESFORCE_CALLBACK_URI_BASE)
console.log('settings-dynamic-->', env.SALESFORCE_CALLBACK_URI_BASE)
console.log('settings-process.env->', process.env.SALESFORCE_CALLBACK_URI_BASE)

They all show the "old value"

  1. I entered node and explicitly set the process.env.SALESFORCE_CALLBACK_URI_BASE to a new value, but when I ran npm run dev this value was overwritten.

  2. I explicitly installed dotenv package.

  3. My .env file is at the base of the project and I also created a second .env.local with the correct values.

  4. I restarted my VSCode.

  5. In svelte.config.js I added env property.

const config = {
    preprocess: vitePreprocess(),
    kit: {
        env: {
            dir: '.',
        },
        adapter: adapter()
    }
};
  1. Deleted .svelte-kit/ and node_modules/.vite and used npm run dev.

The above steps were done exclusive of each other and they did not work.

1

There are 1 best solutions below

0
Shri P On

I realized that the values were being persisted in my bash env.

You can print it by typing this in the terminal

env

From this GH comment to "Show environment contributions" for my VSCode integrated zsh terminal, I checked that the ms-python.python VSCode extension had an Activated environment for ~/.pyenv/versions/3.10.2/bin/python which was bringing those values. (Maybe from an earlier project? I am not sure where they came from.)

so I used this SO answer to unset those "old values".

unset SALESFORCE_CALLBACK_URI_BASE

After this svelte read my values correctly. Still a bit weird why in a TS/JS project were python interpreter values being interfering.