Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variables Not Working After Project Build #10374

Open
mamun2519 opened this issue Dec 29, 2024 · 2 comments
Open

Environment Variables Not Working After Project Build #10374

mamun2519 opened this issue Dec 29, 2024 · 2 comments

Comments

@mamun2519
Copy link

Reproduction

Description:
I am facing an issue where environment variables defined in the .env file at the project root are not working after building the project.

Steps to Reproduce:

Define environment variables in a .env file at the project root:

PORT=3000  
MONGODB_URI=xyz  

Configure dotenv in vite.config.js as follows:

import dotenv from "dotenv";  
import path from "path";  

// dotenv.config({ path: "./.env" });  
dotenv.config({ path: path.join(process.cwd(), "/.env") });  

declare module "@remix-run/node" {  
  interface Future {  
    v3_singleFetch: true;  
  }  
}  

Build the project.

System Info

Remix Framework Version: remix v2
Node.js Version: >=20.0.0
Operating System: Ubuntu 24.04.1 LTS

Used Package Manager

npm

Expected Behavior

The environment variables should be available and properly loaded after building the project.

Actual Behavior

The environment variables do not work as expected after the project is built.

Additional Context:
I suspect this might be related to how dotenv or Remix handles environment variables during the build process. Please let me know if additional configurations are needed.

@sergiodxa
Copy link
Member

In Remix, dotenv is only used on development, when running your app in production mode after building it it won't use dotenv automatically for your

You can manually use dotenv in production if you want but the recommendation (even from the authors of the .env file) is to only use it for dev and in production use actual env variables in your system.

@mamun2519
Copy link
Author

I appreciate your help. am resolving this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants