Invalid environment variables

❌ Invalid environment variables: { ENCRYPTION_KEY: [ 'Invalid input' ] } /node_modules/@t3-oss/env-nextjs/dist/index.mjs:1
11 Replies
Mirza
MirzaOP14mo ago
const fs = require('fs');
const dotenv = require('dotenv');

// Load the values from the source .env file
const sourceEnv = dotenv.parse(fs.readFileSync('.env'));

// Add the encryption key to the source .env
sourceEnv.ENCRYPTION_KEY = "'6G5C97Hlai0WqeDeDljhTPBZVEDyls/9'";

// Convert the sourceEnv object back to a string
const updatedEnv = Object.entries(sourceEnv).map(([key, value]) => `${key}=${value}`).join('\n');

// Write the updated .env file
fs.writeFileSync('apps/web/.env', updatedEnv);
const fs = require('fs');
const dotenv = require('dotenv');

// Load the values from the source .env file
const sourceEnv = dotenv.parse(fs.readFileSync('.env'));

// Add the encryption key to the source .env
sourceEnv.ENCRYPTION_KEY = "'6G5C97Hlai0WqeDeDljhTPBZVEDyls/9'";

// Convert the sourceEnv object back to a string
const updatedEnv = Object.entries(sourceEnv).map(([key, value]) => `${key}=${value}`).join('\n');

// Write the updated .env file
fs.writeFileSync('apps/web/.env', updatedEnv);
Jochem
Jochem14mo ago
remove one of the set of quotes around that encryption key
Mirza
MirzaOP14mo ago
did but still same error
Mirza
MirzaOP14mo ago
No description
Joao
Joao14mo ago
Error message suggests an error on line 4, or when parsing the file. Double check the original .env file for extra spaces, etc.
Mirza
MirzaOP14mo ago
What? I don't have any spaces in encryption key
Joao
Joao14mo ago
Try with:
const sourceEnv = dotenv.parse(fs.readFileSync('.env', 'utf-8');
const sourceEnv = dotenv.parse(fs.readFileSync('.env', 'utf-8');
Mirza
MirzaOP14mo ago
const sourceEnv = dotenv.parse(fs.readFileSync('.env', 'utf-8'));
const sourceEnv = dotenv.parse(fs.readFileSync('.env', 'utf-8'));
still same error
Joao
Joao14mo ago
I'd suggest then you remove keys from your .env file until it stops throwing errors, as something there is formatted incorrectly or is otherwise invalid. Also, did you try with 'utf8' as well?
Mirza
MirzaOP14mo ago
yeah
Mirza
MirzaOP14mo ago
Want results from more Discord servers?
Add your server