Confusing Docs for Environment Variables
Unanswered
Jersey Wooly posted this in #help-forum
Jersey WoolyOP
The Nextjs website, in the section for environment variables, at some point tells me to create a file called envConfig.ts with this content:
Then that same section of the docs goes on to say, "Then, you can import the configuration where needed. For example:", in a file called orm.config.ts they show this code:
The import there looks OK, but I get an error because "Cannot find name 'defineConfig'."
I realise this is only an example, and that
import { loadEnvConfig } from '@next/env'
const projectDir = process.cwd()
loadEnvConfig(projectDir)Then that same section of the docs goes on to say, "Then, you can import the configuration where needed. For example:", in a file called orm.config.ts they show this code:
import './envConfig.ts'
export default defineConfig({
dbCredentials: {
connectionString: process.env.DATABASE_URL!,
},
})The import there looks OK, but I get an error because "Cannot find name 'defineConfig'."
I realise this is only an example, and that
defineConfig probably has something to do with whatever ORM uses the file called orm.config.ts, but that doesn't help me understand how to "import the configuration where needed".3 Replies
where are you trying to load environment variables?
Jersey WoolyOP
I only need to load them in nextjs. I've come right, thanks, by just using this:
It didn't work at first because I treated the value for
export const appConfig = {
urlConfig: {
baseUrl: process.env.NEXT_PUBLIC_BASE_URL!,
//baseUrl: "http://localhost:3000"
}
};It didn't work at first because I treated the value for
NEXT_PUBLIC_BASE_URL in the .env.development file like a string variable and surrounding it with quotes. That caused problems that made me look in the wrong direction. Thanks anyway.