Error locating autoloader. Please run composer install

I have a Bedrock site that uses Acorn and Sage 10 and if I understand correctly I should install Acorn in the root directory where I have my Bedrock composer.json. If I do so, I get an error message when I’m trying to load my site: Error locating autoloader. Please run composer install.

If I use Composer to install Acorn in my theme directly, my theme loads without issues.

I’d like to only use the composer.json in the root of my Bedrock site. According to the documentation this should be possible and should actually be the way to install Acorn.

My composer.json in Bedrock:

{
  "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://composer.deliciousbrains.com/1B685B1EFADDB766CF01980637F582D0" },
    {
      "type": "package",
      "package": {
        "name": "advanced-custom-fields/advanced-custom-fields-pro",
        "version": "5.12.2",
        "type": "wordpress-plugin",
        "dist": {
          "type": "zip",
          "url": "https://connect.advancedcustomfields.com/index.php?a=download&p=pro&k={%ACF_PRO_KEY}&t=5.12.2"
        },
        "require": {
          "composer/installers": "^2.0",
          "ffraenz/private-composer-installer": "^5.0"
        }
      }
    }
  ],
  "require": {
    "php": ">=7.4",
    "composer/installers": "^2.0",
    "vlucas/phpdotenv": "^5.4",
    "oscarotero/env": "^2.1",
    "wp-cli/wp-cli-bundle": "^2.6",
    "roots/acorn": "^2",
    "roots/bedrock-autoloader": "^1.0",
    "roots/bedrock-disallow-indexing": "^2.0",
    "roots/wordpress": "5.9.2",
    "roots/wp-config": "1.0.0",
    "roots/wp-password-bcrypt": "1.1.0",
    "advanced-custom-fields/advanced-custom-fields-pro": "^5",
    "deliciousbrains-plugin/wp-migrate-db-pro": "^2",
    "wpackagist-plugin/acf-content-analysis-for-yoast-seo": "^3",
    "wpackagist-plugin/akismet": "^4",
    "wpackagist-plugin/all-in-one-schemaorg-rich-snippets": "^1",
    "wpackagist-plugin/broken-link-checker": "^1",
    "wpackagist-plugin/duplicate-page": "^4",
    "wpackagist-plugin/gravity-forms-google-analytics-event-tracking": "^2",
    "wpackagist-plugin/hide-my-site": "^2",
    "wpackagist-plugin/hreflang-manager-lite": "^1",
    "wpackagist-plugin/media-cleaner": "^6",
    "wpackagist-plugin/multilingual-press": "^2",
    "wpackagist-plugin/query-monitor": "^3",
    "wpackagist-plugin/real-time-validation-for-gravity-forms": "^1",
    "wpackagist-plugin/redirection": "^5",
    "wpackagist-plugin/regenerate-thumbnails": "^3",
    "wpackagist-plugin/tinymce-advanced": "^5",
    "wpackagist-plugin/w3-total-cache": "^2",
    "wpackagist-plugin/wordpress-seo": "^18",
    "wpackagist-plugin/wp-mail-smtp": "^3",
    "wpackagist-plugin/wp-sentry-integration": "^4"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.6.2",
    "roave/security-advisories": "dev-latest"
  },
  "autoload": {
    "psr-4": {
      "App\\": "web/app/themes/theme/app/"
    }
  },
  "post-autoload-dump": [
    "Roots\\Acorn\\ComposerScripts::postAutoloadDump"
  ],
  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "allow-plugins": {
      "composer/installers": true,
      "roots/wordpress-core-installer": true,
      "ffraenz/private-composer-installer": true
    }
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "extra": {
    "acorn": {
      "providers": [
        "App\\Providers\\ThemeServiceProvider"
      ]
    },
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "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"
    ]
  }
}

My composer.json in my 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": "^7.4|^8.0",
    "roots/acorn": "^2.0"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.6"
  },
  "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)."
  },
  "post-autoload-dump": [
    "Roots\\Acorn\\ComposerScripts::postAutoloadDump"
  ],
  "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"
      ]
    }
  }
}

Your error is unrelated to where you install Acorn.

Regardless of where Acorn is installed, you must run composer install in the theme folder in order to build the autoloader, which is used to load parts of Sage even if no composer packages are installed there.