I have a .env
file and I use dotenv
package to manage that file and supply it to Quasar in quasar.config.js
:
module.exports = configure(function (ctx) {
return {
// ...
build: {
// ...
env: {
...require('dotenv').config().parsed
}
}
// ...
}
}
From my experience, I know that on Netlify I get the issue because the .env
file doesn't exist on the server when the build command runs in the folder dist/spa
.
I tried adding environment variables there via their UI but still, the error is there even after re-deploying by clearing cache.
It's my first time deploying on Netlify and I thought it would be easy but I don't know how to solve the environment variables issue.
I have deployed to Github pages and on other servers using Github actions, and the way I did it was:
- Add GitHub secrets with the content of
.env
- Creating a
.env
file on the fly:
- name: Create env
env:
ENV: ${{ secrets.ENV }}
run: echo "$ENV" > ./.env
That works great, but for my project, I wanted to try Netlify because it's easy and we don't need GitHub actions to enable automatic deployment. Plus it has some extra features that I like.
So what am I missing here?
CodePudding user response:
I don't know if it's the right way to do it, but I solved it by updating the quasar.config.js
and actually re-defining all my environment variables:
module.exports = configure(function (ctx) {
require('dotenv').config()