dotenv:init seems to generate a non working load.environment.php

Created on 13 May 2025, 9 days ago

Problem/Motivation

The load.environment.php file generated by drush dotenv:init command generate fatal errors

For it to work, i needed to adapt from


/**
 * This file is included very early. See autoload.files in composer.json and
 * https://getcomposer.org/doc/04-schema.md#files
 */

use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;

/**
 * Load any .env file. See /.env.example.
 */
$dotenv = new Dotenv(__DIR__);
try {
  $dotenv->load();
}
catch (InvalidPathException $e) {
  // Do nothing. Production environments rarely use .env files.
}

To


/**
 * This file is included very early. See autoload.files in composer.json and
 * https://getcomposer.org/doc/04-schema.md#files
 */

use Dflydev\DotAccessData\Exception\InvalidPathException;
use Symfony\Component\Dotenv\Dotenv;

/**
 * Load any .env file. See /.env.example.
 */
$dotenv = new Dotenv();
try {
  $dotenv->load('/app/.env');
}
catch (InvalidPathException $e) {
  // Do nothing. Production environments rarely use .env files.
}

I suppose this code is obsolete with the latest dotenv dependancies

Steps to reproduce

Install the module , throw drush dotenv:init

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇫🇷France Thony

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Thony
  • 🇧🇪Belgium dieterholvoet Brussels

    Dflydev\DotAccessData\Exception\InvalidPathException is not related to the Symfony Dotenv component, so there's no point in catching it. Also, these files do not look like the one that this module provides. I'm guessing there already was a load.environment.php present before you ran the command. You can find the file that this module provides here.

Production build 0.71.5 2024