Closed igorMondu closed 1 month ago
Start a new pull request in StackBlitz Codeflow.
It seems this happens if the value is not used: https://stackblitz.com/edit/vitejs-vite-sur928?file=main.js,package.json&terminal=dev
For a workaround, I guess you can use import.meta.env && import.meta.env.REACT_APP_MERCHANT_ENVIRONMENT === 'development'
instead.
https://stackblitz.com/edit/vitejs-vite-me95gs?file=src%2FApp.tsx
@sapphi-red This bug is more serious than it seemed. It completely breaks in the old browser even with vite legacy plugin. Wherever optional chaining is used, the whole application crashes in old browsers with the message:
Uncaught SyntaxError: Unexpected token ?
Can you put some higher priority on fixing this?
@igorMondu I think that's a different issue. Please create a new issue with a reproduction.
Closing as this seems to be working since somewhere around 5.0.0.
Describe the bug
After upgrading from Vite 3.2.7 to 4.4.9, I am unable to make a production build.
I use @vitejs/plugin-legacy in my project and it seems that the combination vitejs 4 + legacy plugin causes build to failed when optional chaining is used with env property.
Having the above code in the project will cause the production build to fail. This works perfectly fine with Vite 3.2.7.
If I remove optional chaining (?) after .env, vite 4 also works, so this is a bug in Vite v4.
And no, I can not remove chaining to resolve this issue. I use the same helper file in PlayWright, and it fails without optional chaining.
Reproduction
https://stackblitz.com/edit/vitejs-vite-qirgcx
Steps to reproduce
npm run build
System Info
Used Package Manager
npm
Logs
Validations