bedrock: oscarotero/env v2.1.0 Class 'Env' not found

Description

I have recently updated composer and got the oscarotero/env v2.1.0 package. Since then I keep getting this error:

Fatal error: Uncaught Error: Class 'Env' not found in /myproject/config/application.php:6

Steps to reproduce

  1. Update composer to v2.1.0 on package oscarotero/env
  2. Check your local repository

Expected behavior: [What you expect to happen]

Expected to run site normally.

Actual behavior: [What actually happens]

Throws error Fatal error: Uncaught Error: Class 'Env' not found in /myproject/config/application.php:6

Reproduces how often: [What percentage of the time does it reproduce?]

100%

Versions

oscarotero/env v2.1.0

Additional information

This is the content of the referenced file, where Env::init() corresponds to line 6:

<?php

$root_dir = dirname(__DIR__);
$webroot_dir = $root_dir . '/public';

Env::init();

// Use Dotenv to set required environment variables and load .env file in root
$dotenv = new Dotenv\Dotenv($root_dir);
if (file_exists($root_dir . '/.env')) {
    $dotenv->load();
    try {
      $dotenv->required('DATABASE_URL')->notEmpty();
    } catch (Exception $e) {
      $dotenv->required(['DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL']);
    }
}

It seems as if the package were not loaded since the Env Class doesn’t load. Ideas?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

SO how do we fix this ? I am stuck here aswell…

@TangRufus Sure, I’ll try to get a PR ready over the coming weekend.

Download https://patch-diff.githubusercontent.com/raw/roots/bedrock/pull/530.diff and $ git apply it. However, depends on how much change you made and how “out of sync” your code is, it might not work. For a small patch like #530, manually copy and paste the changes might be easier.

Props to @austinpray