preact-cli
preact-cli copied to clipboard
Issue with env variables when preact-cli versions get mixed up
At the time of the writing,
yarn global add preact-cli adds [email protected] globally and
preact create ... creates a project with [email protected] in the package.json
It seems that there is a difference between 2.x.x and 3.x.x that cause this silent error with the env vars handling.
The error being: nothing in process.env whatever I tried.
Fixed with yarn global add preact-cli@3
Originally posted by @toniopelo in https://github.com/preactjs/preact-cli/issues/762#issuecomment-638245265
A fix on [email protected] to avoid generating a package.json requiring preact-cli@3 might do the trick?
Well the CLI doesn't generate a package.json file, all new project content comes from the templates. Preact-CLI v3 is used on all templates (at least I think it is used on all) because it's in an RC stage which should be stable enough.
What you have globally installed shouldn't actually matter, as your project will be using your per-project installation. The global install is just used for setting up new projects, nothing more.
Have you tried following the suggested solution from the issue you linked? Seems to be working just fine. dotenv-safe requires you have a .env.example file with x= for each variable you want to use. Then you can access the value with process.env.x where x is supplied from your .env file or system.
I don't think there's any possible way for the CLI to mess with your systems env vars to the point where none can be found at all. It sounds more like whatever tool you're using to access the variables is either set up incorrectly or no longer works.
@RyanChristian4427 Thank you for the answer.
Hmmm, I see.. I wasn't aware that the package.json was provided by the template.
That's weird because all the proposed solution were failing (silently). I had an empty process.env object. The only thing that seems to make it work was to regenerate the project with preact-cli@3 installed globally (and with the exact same code and preact.config.js file).
I'm gonna try to reproduce.
Just a note - we are generally recommending folks use preact-cli v3 in all cases. It'll become the official release in a week or so.