Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables aren't refreshed when using intlayerPlugin from "vite-intlayer #19306

Closed
7 tasks done
seaders opened this issue Jan 28, 2025 · 1 comment
Closed
7 tasks done

Comments

@seaders
Copy link

seaders commented Jan 28, 2025

Describe the bug

This is basically the exact same situation as a previous bug I brought up, #18993

The reason this happens is because of 2 areas of this plugin, where they use dotenv.config to load the env files for their app (if things haven't been set up yet). They use dotenv because that side of the app isn't vite specific

https://github.com/aymericzip/intlayer/blob/36cad493b0a2162c0007d95ac1bff5d2dcfca601/packages/%40intlayer/config/src/envVariables/loadEnvFile.ts#L6

and

https://github.com/aymericzip/intlayer/blob/36cad493b0a2162c0007d95ac1bff5d2dcfca601/packages/vite-intlayer/src/intlayerPlugin.ts#L38

Per the advice I got from the previous issue, it seems like, again, the mutating of process.env broke the env var processing, and I'm 99% sure the same is happening here. I've tried finding which is a "safe" way to set env vars from plugins, but I wasn't actually able to find any conclusive instructions in the docs.

Now, I am in discussion with the dev of that application, but, realistically, I'm not sure if this is really correct. Should vite's env vars be this... fragile?

I had experienced a fully broken (dev) build from a previous version of this, when they ran dotenv.config, but in the wrong order,

aymericzip/intlayer@59f042d

They ran

dotenv.config({ path: ['.env', .env.${env}, .env.${env}.local] });

instead of

dotenv.config({ path: [.env.${env}.local, .env.${env}, '.env'] });

Which wiped out .local settings I was using for my build. That's "their bad", of course, but should vite not protect, or at least warn against that?

Reproduction

https://stackblitz.com/~/github.com/SuperStreaming/intlayerapp?file=.env.development.local

Steps to reproduce

Open the stackblitz, wait for it to load, then change the VITE_MY_ENV_VAR to anything you want. There's no live reload, and even if you save the edited file and the server restarts, there's still no update on the page.

System Info

System:
    OS: macOS 15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 168.51 MB / 16.00 GB
    Shell: 5.2.37 - /usr/local/bin/bash
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.11.1/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.15.2 - ~/.nvm/versions/node/v20.11.1/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4 
    @vitejs/plugin-react-swc: ^3.7.2 => 3.7.2 
    vite: ^6.0.3 => 6.0.7

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

Is your reproduction working now as fixed by aymericzip/intlayer#91?
I think the underlying issue (before their fix) seems same as #17689, so let me close this. Please comment on the original issue if you'd like to share some ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants