diff --git a/core/lib/Drupal/Core/Asset/Exception/InvalidCssDefinitionException.php b/core/lib/Drupal/Core/Asset/Exception/InvalidCssDefinitionException.php
new file mode 100644
index 0000000..def8439
--- /dev/null
+++ b/core/lib/Drupal/Core/Asset/Exception/InvalidCssDefinitionException.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Asset\Exception\InvalidCssDefinitionException.
+ */
+
+namespace Drupal\Core\Asset\Exception;
+
+/**
+ * Defines an exception if the library file is not keyed by a category.
+ */
+class InvalidCssDefinitionException extends \RunTimeException {
+
+}
diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
index 26ba97a..b3354dc 100644
--- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
+++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
@@ -8,6 +8,7 @@
 namespace Drupal\Core\Asset;
 
 use Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException;
+use Drupal\Core\Asset\Exception\InvalidCssDefinitionException;
 use Drupal\Core\Asset\Exception\InvalidLibraryFileException;
 use Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -122,12 +123,21 @@ public function buildByExtension($extension) {
         //   and only once prior to rendering out an HTML page.
         if ($type == 'css' && !empty($library[$type])) {
           foreach ($library[$type] as $category => $files) {
+            if (empty($files)) {
+              throw new InvalidCssDefinitionException(sprintf("You have to key the css files in the %s.library.yml file by category ('%s' seems to be a file name, allowed categories are Base, Layout, Component, State, Theme)", $extension, $category));
+            }
             foreach ($files as $source => $options) {
               if (!isset($options['weight'])) {
                 $options['weight'] = 0;
               }
-              // Apply the corresponding weight defined by CSS_* constants.
-              $options['weight'] += constant('CSS_' . strtoupper($category));
+              // Check if the category is valid or not and apply the
+              // corresponding weight defined by the CSS_* constants.
+              if (defined('CSS_' . strtoupper($category))) {
+                $options['weight'] += constant('CSS_' . strtoupper($category));
+              }
+              else {
+                throw new InvalidCssDefinitionException(sprintf("You have used an invalid category %s in %s.libraries.yml. Allowed categories are Base, Layout, Component, State, Theme)", $category, $extension));
+              }
               $library[$type][$source] = $options;
             }
             unset($library[$type][$category]);
diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module
index 5c35856..f89e772 100644
--- a/core/modules/system/tests/modules/common_test/common_test.module
+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -175,7 +175,9 @@ function common_test_library_info_build() {
     $libraries['dynamic_library'] = [
       'version' => '1.0',
       'css' => [
-        'common_test.css' => [],
+        'theme' => [
+          'common_test.css' => [],
+        ],
       ],
     ];
   }
diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
index 9a8b4dd..169d2f4 100644
--- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
+++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
@@ -1,6 +1,7 @@
 example:
   css:
-    css/example.js: {}
+    theme:
+      css/example.css: {}
   dependencies:
     - external/example_external
     - example_module/example
