Closed diadal closed 9 months ago
Hi @diadal! 👋
It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, StackBlitz, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.
Without a proper reproduction, your issue will have to get closed.
Thank you for your collaboration. 👏
Hi,
This is simply how Vite 5 works. The production code should directly reference the full process.env.[X] which will get replaced inline with what you define it with. A console.log(process.env)
should not exist in the production code.
in a short word
const appVersionX = process.env.VITE_APP_VERSION;
console.log('appVersionX: ', appVersionX); // worked
const evn_data = process.env;
const appVersion = evn_data?.VITE_APP_VERSION; // not working
console.log('appVersion: ', appVersion);
The process.env.[X] gets replaced inline, for multiple reasons, including security. It is not an Object created in memory that you can handle like any other. Directly write process.env.VITE_APP_VERSION so it can get matched and replaced in your production code. The process.env
should not be assignable, and one of the reasons for this is that if your code has access to it then so is a user of your UI with an opened devtools, which poses a great security risk.
nice
this resolved the issue for me
import { boot } from 'quasar/wrappers';
const all_env = {
VITE_APP_TITLE: process.env.VITE_APP_TITLE,
VITE_APP_NAME: process.env.VITE_APP_NAME,
VITE_APP_VERSION: process.env.VITE_APP_VERSION,
VITE_APP_COLOR: process.env.VITE_APP_COLOR,
VITE_GOOGLE_KEY: process.env.VITE_GOOGLE_KEY,
VITE_FIREBASE_API_KEY: process.env.VITE_FIREBASE_API_KEY,
VITE_FIREBASE_DOMAIN: process.env.VITE_FIREBASE_DOMAIN,
VITE_FIREBASE_URL: process.env.VITE_FIREBASE_URL,
VITE_FIREBASE_PROJECT_ID: process.env.VITE_FIREBASE_PROJECT_ID,
VITE_FIREBASE_BUK: process.env.VITE_FIREBASE_BUK,
VITE_FIREBASE_MSG_ID: process.env.VITE_FIREBASE_MSG_ID,
VITE_FIREBASE_APP_ID: process.env.VITE_FIREBASE_APP_ID,
VITE_FIREBASE_MEN: process.env.VITE_FIREBASE_MEN,
VITE_PUB_KEY_DEV: process.env.VITE_PUB_KEY_DEV,
VITE_PUB_KEY_PRO: process.env.VITE_PUB_KEY_PRO,
};
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$all_env: typeof all_env;
}
}
export default boot(({ app }) => {
app.config.globalProperties.$all_env = all_env;
});
Just be aware that all your keys will now be part of the production build (in plain form) whether you use them or not.
Yes I know
What happened?
all
process.env
values return undefined only on pro modequasar b
but working on dev modequasar d
What did you expect to happen?
should work the same way as the dev mode work
Reproduction URL
no link
How to reproduce?
run this
quasar b
Flavour
Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)
Areas
SPA Mode, Capacitor Mode
Platforms/Browsers
Firefox, Chrome, Safari, iOS, Android
Quasar info output
Relevant log output
No response
Additional context
Build succeeded
Build mode............. spa Pkg quasar............. v2.14.3 Pkg @quasar/app-vite... v2.0.0-beta.1 Pkg vite............... v5.1.1 Debugging.............. no Publishing............. no Browser target......... es2019|edge88|firefox78|chrome87|safari13.1