Illuminate\Container\Container::get error after migrate Sage 9 to Sage 10

Hello,

We have a website running with the Bedrock structure.
We updated our theme to switch the Sage version from 9 to 10, but when we activate the theme, the site crashed and gave us this error:

PHP Fatal error:  Declaration of Illuminate\Container\Container::get(string $id) must be compatible with Psr\Container\ContainerInterface::get($id) in /var/www/html/vendor/illuminate/container/Container.php on line 714

We never install the package illuminate, so we thought that is a package use by a Sage/roots dependence. We tried to remove the dependencies, re-downloaded them, but nothings worked. Maybe we forgot to install a dependency, or there may be a conflict with one of our dependency…

composer.json (root of project)

{
  "name": "roots/bedrock",
  "type": "project",
  "license": "MIT",
  "description": "WordPress boilerplate with Composer, easier configuration, and an improved folder structure",
  "homepage": "https://roots.io/bedrock/",
  "authors": [
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    }
  ],
  "keywords": [
    "bedrock", "composer", "roots", "wordpress", "wp", "wp-config"
  ],
  "support": {
    "issues": "https://github.com/roots/bedrock/issues",
    "forum": "https://discourse.roots.io/category/bedrock"
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org",
      "only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
    },
    {
      "type": "composer",
      "url": "https://connect.advancedcustomfields.com"
    }
  ],
  "require": {
    "php": ">=8.1",
    "composer/installers": "^2.2",
    "vlucas/phpdotenv": "^5.5",
    "oscarotero/env": "^2.1",
    "roots/bedrock-autoloader": "^1.0",
    "roots/bedrock-disallow-indexing": "^2.0",
    "roots/wordpress": "6.2.2",
    "roots/wp-config": "1.0.0",
    "roots/wp-password-bcrypt": "1.1.0",
    "roots/acorn": "^3.1",
    "woody-wordpress/woody-acf-sync": "1.3.5",
    "wp-cli/wp-cli-bundle": "v2.5.0",
    "wpackagist-plugin/acf-role-selector-field": "^3.0",
    "wpackagist-plugin/acf-to-rest-api": "3.3.*",
    "wpackagist-plugin/backwpup": "3.*",
    "wpackagist-plugin/enable-media-replace": "3.6.*",
    "wpackagist-plugin/enhanced-media-library": "2.8.*",
    "wpackagist-plugin/content-control": "^1.1",
    "wpackagist-plugin/duplicate-page": "4.4.*",
    "wpackagist-plugin/media-sync": "1.2.*",
    "wpackagist-plugin/minmax-quantity-for-woocommerce": "1.3.*",
    "wpackagist-plugin/miniorange-adfs-login": "2.1.*",
    "wpackagist-plugin/mpdf-addon-for-pdf-invoices": "1.0.*",
    "wpackagist-plugin/post-types-order": "1.9.*",
    "wpackagist-plugin/prevent-direct-access": "2.7.*",
    "wpackagist-plugin/simple-history": "3.2.*",
    "wpackagist-plugin/smtp-mailer": "1.1.*",
    "wpackagist-plugin/subscribe-to-category": "2.6.*",
    "wpackagist-plugin/taxonomy-terms-order": "1.6",
    "wpackagist-plugin/user-role-editor": "4.61.*",
    "wpackagist-plugin/view-admin-as": "1.8.*",
    "wpackagist-plugin/woocommerce": "7.7.2",
    "wpackagist-plugin/woo-orders-tracking": "1.2.*",
    "wpackagist-plugin/wordfence-login-security": "1.1.*",
    "wpackagist-plugin/wordpress-importer": "0.7",
    "wpackagist-plugin/wp-crontrol": "1.*",
    "wpackagist-plugin/wp-rest-api-authentication": "2.6.*",
    "wpackagist-plugin/wp-security-audit-log": "4.4.*",
    "wpengine/advanced-custom-fields-pro": "^6.0.7"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.7.1",
    "roave/security-advisories": "dev-latest"
  },
  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "allow-plugins": {
      "composer/installers": true,
      "roots/wordpress-core-installer": true
    }
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": [
        "type:wordpress-muplugin",
        "wpackagist-plugin/acf-role-selector-field",
        "wpackagist-plugin/acf-to-rest-api",
        "wpackagist-plugin/backwpup",
        "wpackagist-plugin/content-control",
        "wpackagist-plugin/duplicate-page",
        "wpackagist-plugin/enable-media-replace",
        "wpackagist-plugin/enhanced-media-library",
        "wpackagist-plugin/media-sync",
        "wpackagist-plugin/post-types-order",
        "wpackagist-plugin/prevent-direct-access",
        "wpackagist-plugin/smtp-mailer",
        "wpackagist-plugin/taxonomy-terms-order",
        "wpackagist-plugin/user-role-editor",
        "wpackagist-plugin/view-admin-as",
        "wpackagist-plugin/wordpress-importer",
        "wpackagist-plugin/wp-crontrol",
        "wpackagist-plugin/subscribe-to-category",
        "wpackagist-plugin/simple-history",
        "wpengine/advanced-custom-fields-pro"
      ],
      "web/app/plugins/{$name}/": [
        "type:wordpress-plugin",
        "wpackagist-plugin/miniorange-adfs-login",
        "wpackagist-plugin/minmax-quantity-for-woocommerce",
        "wpackagist-plugin/mpdf-addon-for-pdf-invoices",
        "wpackagist-plugin/woo-orders-tracking",
        "wpackagist-plugin/woocommerce",
        "wpackagist-plugin/wordfence-login-security",
        "wpackagist-plugin/wp-cassify",
        "wpackagist-plugin/wp-rest-api-authentication",
        "wpackagist-plugin/wp-security-audit-log"
      ],
      "web/app/themes/{$name}/": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "web/wp"
  },
  "scripts": {
    "post-root-package-install": [
      "php -r \"copy('.env.example', '.env');\""
    ],
    "test": [
      "phpcs"
    ],
    "post-autoload-dump": [
      "Roots\\Acorn\\ComposerScripts::postAutoloadDump"
    ]
  }
}

composer.json (theme folder)

{
  "name": "roots/sage",
  "type": "wordpress-theme",
  "license": "MIT",
  "description": "WordPress starter theme with a modern development workflow",
  "homepage": "https://roots.io/sage/",
  "authors": [
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    },
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "QWp6t",
      "email": "hi@qwp6t.me",
      "homepage": "https://github.com/qwp6t"
    },
    {
      "name": "Brandon Nifong",
      "email": "brandon@tendency.me",
      "homepage": "https://github.com/log1x"
    }
  ],
  "keywords": [
    "wordpress"
  ],
  "support": {
    "issues": "https://github.com/roots/sage/issues",
    "forum": "https://discourse.roots.io/"
  },
  "autoload": {
    "psr-4": {
      "App\\": "app/"
    }
  },
  "require": {
    "php": "^8.0"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "3.7.1"
  },
  "suggest": {
    "log1x/sage-directives": "A collection of useful Blade directives for WordPress and Sage (^1.0).",
    "log1x/sage-svg": "A useful SVG directive for inlining SVG's within Blade views (^1.0)."
  },
  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "scripts": {
    "lint": [
      "phpcs --extensions=php --standard=PSR12 app"
    ]
  },
  "extra": {
    "acorn": {
      "providers": [
        "App\\Providers\\ThemeServiceProvider"
      ]
    }
  }
}

package.json in theme folder

{
  "name": "sage",
  "private": true,
  "browserslist": [
    "extends @roots/browserslist-config"
  ],
  "engines": {
    "node": ">=16.0.0"
  },
  "type": "module",
  "scripts": {
    "dev": "bud dev",
    "build": "bud build",
    "lint": "npm lint:js && npm lint:css",
    "lint:js": "eslint resources/scripts",
    "lint:css": "stylelint \"resources/**/*.{css,scss,vue}\"",
    "test": "npm lint"
  },
  "devDependencies": {
    "@babel/core": "^7.22.5",
    "@roots/bud": "6.12.2",
    "@roots/bud-eslint": "6.12.2",
    "@roots/bud-preset-wordpress": "6.12.2",
    "@roots/bud-prettier": "6.12.2",
    "@roots/bud-stylelint": "6.12.2",
    "@roots/bud-tailwindcss": "6.12.2",
    "@roots/eslint-config": "6.12.2",
    "@roots/sage": "6.12.2",
    "postcss": "^8.4.24",
    "postcss-import": "^15.1.0",
    "stylelint-config-standard": "^33.0.0",
    "webpack": "^5.86.0"
  },
  "dependencies": {
    "alpinejs": "^3.12.2"
  }
}

PHP version: 8.1-fpm-alpine
Server: nginx 1.25.0-alpine
Node (for compiling the theme): node-16-alpine

Thanks in advance!

1 Like

Encountered the same issue today, with PHP 8.1 and latest Sage 10 theme. However, the Bedrock site was of older version and already used an older Sage 9 theme. Maybe somewhere is an extraneous class file.

Fatal error: Declaration of Illuminate\Container\Container::get(string $id) must be compatible with Psr\Container\ContainerInterface::get($id)

So Illuminate\Container\Container implements Illuminate\Contracts\Container\Container which itself extends Psr\Container\ContainerInterface.

That ContainerInterface defines the get function without a typed $id parameter (public function get(string $id);). There are multiple PHP files with that same ContainterInterface, but some are outdated, without the typed $id parameter.

The reason was an outdated plugin that used the same illuminate/container classes, but of older version, after updating it to latest version, the issue went away (otherwise the plugin would have to be forked or replaced).

Ran into the same issue today after updating plugins with a Sage 10 project…

The reason for us was an update to the BackWPUp-plugin and pinning it to v4.0.0 resolved the issue for now.

"wpackagist-plugin/backwpup": "4.0.0"

Of course this is very specific to our setup / usage but I wanted to give a heads-up and point anybody towards checking for recent plugin updates and incompatibilities.

1 Like

Sorry for my late answer. I have finally found the solution few weeks ago to solve it, and it was indeed the BackWpUp plugin, so I agree with @evance’s answer.