Index: src/wp-includes/general-template.php
===================================================================
--- src/wp-includes/general-template.php	(revision 38167)
+++ src/wp-includes/general-template.php	(working copy)
@@ -2874,6 +2874,10 @@
 	foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
 		if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
 			foreach ( $dependencies->queue as $handle ) {
+				if ( ! isset( $dependencies->registered[ $handle ] ) ) {
+					continue;
+				}
+
 				/* @var _WP_Dependency $dependency */
 				$dependency = $dependencies->registered[ $handle ];
 				$parsed     = wp_parse_url( $dependency->src );
Index: tests/phpunit/tests/general/resourceHints.php
===================================================================
--- tests/phpunit/tests/general/resourceHints.php	(revision 38167)
+++ tests/phpunit/tests/general/resourceHints.php	(working copy)
@@ -163,4 +163,17 @@
 		$this->assertEquals( $expected, $actual );
 		$this->assertNotContains( $unexpected, $actual );
 	}
+
+	/**
+	 * @ticket 37502
+	 */
+	function test_deregistered_scripts_are_ignored() {
+		$expected = "<link rel='dns-prefetch' href='//s.w.org'>\n";
+
+		wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
+		wp_deregister_script( 'test-script' );
+
+		$actual = get_echo( 'wp_resource_hints' );
+		$this->assertEquals( $expected, $actual );
+	}
 }
