Change default env var PUBLIC_URL
I want to change the PUBLIC_URL env var name to use CDN_URL but when run the refine dev script I have this error
The env-config file has this info
And is localated in the public folder.
5 Replies
Hi @Sebastos. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources provided, there isn't specific information about changing the default
PUBLIC_URL
environment variable to CDN_URL
in refine. However, I can provide some general guidance based on the available information about environment variables in refine and related frameworks.
The error you're encountering suggests that the application is trying to access a file named env-config.js
using the CDN_URL
environment variable, but it's not being properly recognized or parsed.
Here are a few things you can try:
1. Make sure you're using the correct prefix for your environment variable. If you're using Vite with refine, you need to add the "VITE_" prefix to your environment variables. For example, instead of CDN_URL
, try using VITE_CDN_URL
. This is mentioned in the Discord support thread Live provider issue.
2. When referencing the environment variable in your code, use import.meta.env.VITE_CDN_URL
instead of process.env.CDN_URL
.
3. Make sure your .env
file is properly configured and located in the correct directory. The file should be in your project's root directory.
4. If you're using Next.js with refine, you might need to follow Next.js conventions for environment variables. You can refer to the Next.js environment variables blog post for more details.
5. Check if you need to update any build or start scripts to include the new environment variable.
If these suggestions don't resolve the issue, you might need to look into how your specific setup (CRA, Vite, or Next.js) handles custom environment variables and public asset paths. Unfortunately, the provided knowledge sources don't contain enough specific information about changing the PUBLIC_URL
to CDN_URL
in refine to provide a more detailed solution.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@689846866837373077> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
stormy-gold•2mo ago
Hello @Sebastos ,
Sorry but I couldn't understand the problem. are you tying the access
window
object in .env
file? you can't access window on build process.
for more information: https://vite.dev/guide/env-and-modesunny-greenOP•2mo ago
Hi @Alican Erdurmaz ! in the project we set the env variable not in the .env but using other file. We use config-file.js that is inside the public folder. In the deploy pipeline we set the value updating the value in the file and using a regex. The problem was change the name of the variable (from PUBLIC_URL to CDN_URL). We go back the refactor and is working now. Thx for help anyway 😄 !
stormy-gold•2mo ago
I'm glad to hear that 🚀