remix-dev/cli loadEnv should be before readConfig(), In order to use environment variables in remix.config.js #5230
Replies: 6 comments
-
If this is changed. Then the behavior is Remix.config.js would change based on the server, on Remix App Server it will get env variable from .env but on the rest it will not. I think it’s better to keep it on the current way IMO. |
Beta Was this translation helpful? Give feedback.
-
I agree. Not sure why you would need to define environment variables in remix.config. There are many ways to do this already: .env, |
Beta Was this translation helpful? Give feedback.
-
Because I need to load custom routes from database in remix.config.js, and database connection string is in environment variable, although I can use cross-env, it has to be like this: dev: build: |
Beta Was this translation helpful? Give feedback.
-
You can call require("dotenv/config")
module.exports = {
routes(defineRoutes) {
// here use process.env and access the variables from the .env file
}
...more config
} |
Beta Was this translation helpful? Give feedback.
-
One of the benefits of using actual JS files for config instead of JSON. |
Beta Was this translation helpful? Give feedback.
-
Converting this to a Proposal discussion, as per our Development Process. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What version of Remix are you using?
1.3.2
Steps to Reproduce
233: let config = await readConfig(remixRoot);
...
236: await loadEnv(config.rootDirectory);
Expected Behavior
236: await loadEnv(config.rootDirectory);
...
233: let config = await readConfig(remixRoot);
Actual Behavior
233: let config = await readConfig(remixRoot);
...
236: await loadEnv(config.rootDirectory);
Beta Was this translation helpful? Give feedback.
All reactions