Hello! So I’m pretty new to Vite, but not React, so sorry if this an obvious one. I’ve tried a couple things, but I keep getting the above error in the console along with a blank screen once the app goes to sleep. I’m wondering if there’s a best practice for Glitch or if I’m missing something in the Vite docs (which are a little vague, imo)
My code - [ project removed - 7/24/21 ]
Here’s what’s worked temporarily:
changing my .env variables to import.meta.env instead of process.env etc. with VITE_ etc.
adding vite-plugin-environment to my dev dependencies, which allowed me to use process.env without VITE_ (current solution)
I’ve also looked at Vite’s Github and a few people have altered the config file (specifically the mode) but they seem to be dated responses.
Thanks for the great problem description including your code and what you tried!
I don’t think this is going to be “an obvious one” so no worries
Haven’t tried Vite for myself yet but I have seen things like this in other Glitch projects after they go to sleep…
I noticed (from my remix) that your logs say the dev server is running, but it’s a generated_static site. At first I thought this was weird but then I checked an 11ty site, and yep, turns out that’s how they work; run the start command (rather than build).
So that’s probably fine… just a mystery why it would kind of fail to start back up again after going to sleep. And a little hard to repro!
Let us know if you make any headway, and I’m sure other on here will want to chime in
There’s a good chance I’ll just move this project off Glitch soon; I understand that it can be tricky hooking up API’s and one can end up in endless loops / making too many calls to an API. (And in my case, the Pexels API is a bit limited.) That can of course happen with CRA too but Vite runs faster so I imagine more people will be attempting complex projects with it. I’m curious to see how much we’ll be able to do in-browser going forward! I like working with Glitch a lot more than pushing to Github.
I’ll try your code in my config files going forward because I prefer to not use too many plugins.
You’re right that must be the latest Pexels API; I tried to push the project live with Netlify and got the same error in the console. I ended up just moving it into Create React App and it works now.