diff --git a/core/lib/Drupal/Core/DefaultContent/Finder.php b/core/lib/Drupal/Core/DefaultContent/Finder.php
index e6d9b01337d0704bf41b4602294555a5dbe049ec..069c9e8542bcd6a253e84cf570e351d33ff324f8 100644
--- a/core/lib/Drupal/Core/DefaultContent/Finder.php
+++ b/core/lib/Drupal/Core/DefaultContent/Finder.php
@@ -41,9 +41,9 @@ public function __construct(string $path) {
     $graph = $files = [];
     /** @var \Symfony\Component\Finder\SplFileInfo $file */
     foreach ($finder as $file) {
-      /** @var array{_meta: array{uuid: string, depends: array<string, string>|null}} $decoded */
+      /** @var array{_meta: array{uuid: string|null, depends: array<string, string>|null}} $decoded */
       $decoded = Yaml::decode($file->getContents());
-      $uuid = $decoded['_meta']['uuid'];
+      $uuid = $decoded['_meta']['uuid'] ?? throw new ImportException($file->getPathname() . ' does not have a UUID.');
       $decoded['_meta']['path'] = $file->getPath();
       $files[$uuid] = $decoded;
 
diff --git a/core/tests/Drupal/Tests/Core/DefaultContent/FinderTest.php b/core/tests/Drupal/Tests/Core/DefaultContent/FinderTest.php
index d8303959b6f9a5c823b4dc00cac3d84246a2aed0..6abfb5b6733164623b159f4a3c2f5cb0cefcbcc9 100644
--- a/core/tests/Drupal/Tests/Core/DefaultContent/FinderTest.php
+++ b/core/tests/Drupal/Tests/Core/DefaultContent/FinderTest.php
@@ -4,7 +4,9 @@
 
 namespace Drupal\Tests\Core\DefaultContent;
 
+use Drupal\Component\FileSystem\FileSystem;
 use Drupal\Core\DefaultContent\Finder;
+use Drupal\Core\DefaultContent\ImportException;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -32,4 +34,18 @@ public function testFoundDataIsInDependencyOrder(): void {
     $this->assertSame($expected_order, array_slice(array_keys($finder->data), 0, 4));
   }
 
+  /**
+   * Tests that files without UUIDs will raise an exception.
+   */
+  public function testExceptionIfNoUuid(): void {
+    $dir = FileSystem::getOsTemporaryDirectory();
+    $this->assertIsString($dir);
+    /** @var string $dir */
+    file_put_contents($dir . '/no-uuid.yml', '_meta: {}');
+
+    $this->expectException(ImportException::class);
+    $this->expectExceptionMessage("$dir/no-uuid.yml does not have a UUID.");
+    new Finder($dir);
+  }
+
 }