Strapi Issue “Error while running command develop: Could not load js config file…

Lösung für den Strapi-Fehler Could not load js config file beim Start von develop, verursacht durch fehlende Env-Variablen.

Dr. Viktor Walter-Tscharf1 MIN. LESEZEIT
Strapi Issue “Error while running command develop: Could not load js config file…

Strapi Issue “Error while running command develop: Could not load js config file /app/config/env/production/database.js: Cannot read property ‘charAt’ of undefined”

Photo by NeONBRAND on Unsplash

Problem:

I struggle with this error for a little bit. When I finally figured out that this error is in relation to a loading problem of environment variables. Let take a look into the indicated “database.js” file.

const { parse } = require(“pg-connection-string”);
module.exports = ({ env }) => {  
const { host, port, database, user, password } = parse(env(“DATABASE_URL”));
return {  
 defaultConnection: “default”,  
 connections: {  
 default: {  
 connector: “bookshelf”,  
 settings: {  
 client: “postgres”,  
 host,  
 port,  
 database,  
 username: user,  
 password,  
 ssl: { rejectUnauthorized: false }  
 },  
 options: {  
 ssl: false  
 },  
 },  
 },  
 };  
};

On the bold market part we see that an environment variable DATABASE_URL is loaded. Now we need to check if the variable is set in our system.

Therefore execute(printenv):

MacBook-Pro cms % printenv  
TMPDIR=/var/folders/4l/gq_6glf9785879tw17r1px640000gn/T/
XPC_FLAGS=0x0
TERM_PROGRAM_VERSION=433
TERM_PROGRAM=Apple_Terminal
XPC_SERVICE_NAME=0
TERM_SESSION_ID=D6553DCC-0241-4914-9348-B71F225AE395
TERM=xterm-256color
MacBook-Pro cms %

we don’t see any variable for the DATABASE_URL.

Solution:

In a Dockerfile you can use:

ENV DATABASE_URL=postgres://kauznionjswwod:d0c9ae...

In a system environment use:

export DATABASE_URL=postgres://kauznionjswwod:d0c9ae

This should fix the error for you. My problem was that i was setting the wrong variable name. So… be smart and always double-check if you set everything correctly. You can check it with the printenv command.

Happy coding.