Environment Variables Missing `npm run start`
All of my environment variables are missing or undefined after running
npm run build
and npm run start
.
npm run dev
works as expected.
Does the build have access to the .env
file at the root of the project? If not, how do I access them in the build?8 Replies
Environment variables at runtime depend on where you're deploying your code. With the default
node-server
preset you'll need to load your envs at runtime with something like dotenv
I didn't have to do that with SolidStart 0.5.9.
Did that change with 1.0?
Also, you said: "With the default node-server preset, you'll need to load your envs at runtime with something like
dotenv
"
Are there any references you can point me to?
For context... I'm just trying to run npm start
on my local computer for now.
And I'm trying to access the variables with process.env.API_KEY
when I'm using "use server";
I didn't have to do that with SolidStart 0.5.9. Did that change with 1.0?Not sure soz, maybe the old version loaded env files automatically
Are there any references you can point me to?Nah, there should probably be something about it in the docs
And I'm trying to access the variables with process.env.API_KEY
when I'm using "use server";
Yeah Nitro doesn't automatically load env files with the node-server
preset (issue), perhaps it should but for now adding dotenv
in entry-server
might workOk... just to be clear, you said:
Nah, there should probably be something about it in the docs
Which docs? SolidStart, dotenv, Nitro, Vite?
I think technically it's a Nitro responsibility, but for sake of people just trying out Start there should probably be a section in our docs about it
Haha. I agree. It would be helpful if it was covered in the Start docs.
Thanks for the help. I'll keep digging into it.
I just deployed a temp site to Vercel and added my variables, and it works. I might have to use that method for now.
I'm 4-5 hours into this, and I've gotten nowhere.
Sorry, I missed this. Yes, I tried that as well, and it didn't work.