diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index b55a4e3760868ae343f84c3c2327e08ce2e2ad44..3e62558e784ed03301d2d12bb1ec206c9aede066 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -1978,7 +1978,7 @@ downsweep hsc_env old_summaries excl_mods allow_dup_roots
         getRootSummary :: Target -> IO (Either ErrMsg ModSummary)
         getRootSummary (Target (TargetFile file mb_phase) obj_allowed maybe_buf)
            = do exists <- liftIO $ doesFileExist file
-                if exists
+                if exists || isJust maybe_buf
                     then Right `fmap` summariseFile hsc_env old_summaries file mb_phase
                                        obj_allowed maybe_buf
                     else return $ Left $ mkPlainErrMsg dflags noSrcSpan $
diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index 744841a63d041a1877e70e5c27b63cd8c806fd71..e75b2457f04bde87502c9c10ba16a9b59276d4f1 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -517,6 +517,11 @@ data Target
       --
       -- Since GHC version 8.10 modules which require preprocessors such as
       -- Literate Haskell or CPP to run are also supported.
+      --
+      -- If a corresponding source file does not exist on disk this will
+      -- result in a 'SourceError' exception if @targetId = TargetModule _@
+      -- is used. However together with @targetId = TargetFile _@ GHC will
+      -- not complain about the file missing.
     }
 
 data TargetId
diff --git a/testsuite/tests/ghc-api/target-contents/TargetContents.hs b/testsuite/tests/ghc-api/target-contents/TargetContents.hs
index db02dbde2bbad9c9e6b351bf12954c89fae1a831..eaa30697f88b7bf1f6ef032cfee69001dbea6ad2 100644
--- a/testsuite/tests/ghc-api/target-contents/TargetContents.hs
+++ b/testsuite/tests/ghc-api/target-contents/TargetContents.hs
@@ -90,8 +90,7 @@ main = do
 
 data Sync
     = OnDisk   -- | Write generated module to disk
-    | InMemory -- | Only fill targetContents, place an empty dummy module
-               -- on disk though to make Finder shut up though.
+    | InMemory -- | Only fill in targetContents.
 
 ppSync OnDisk   = "D"
 ppSync InMemory = "M"
diff --git a/testsuite/tests/ghc-api/target-contents/TargetContents.stderr b/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
index b0a363c1e53025c4560198f3da25d3166231f0e6..2743f5135ed201a09dfa189c4ac9c6fd98f45841 100644
--- a/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
+++ b/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
@@ -3,8 +3,6 @@
 A.hs:3:5: error: Variable not in scope: z
 == CPP_D
 == CPP_M
-can't find file: A.hs
-
 == Dep_DD_AB
 == Dep_Error_DD_AB
 
@@ -13,33 +11,27 @@ B.hs:3:5: error: Variable not in scope: z
 
 B.hs:3:5: error: Variable not in scope: z
 == Dep_MM_AB
-can't find file: A.hs
-can't find file: B.hs
-
 == Dep_Error_MM_AB
-can't find file: A.hs
-can't find file: B.hs
 
+B.hs:3:5: error: Variable not in scope: z
 == Dep_Error_MM_A
-can't find file: A.hs
 
+A.hs:3:1: error:
+    Could not find module ‘B’
+    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
 == Dep_DM_AB
-can't find file: B.hs
-
 == Dep_Error_DM_AB
-can't find file: B.hs
 
+B.hs:3:5: error: Variable not in scope: z
 == Dep_Error_DM_A
 
 A.hs:3:1: error:
     Could not find module ‘B’
     Use -v (or `:set -v` in ghci) to see a list of the files searched for.
 == Dep_MD_AB
-can't find file: A.hs
-
 == Dep_Error_MD_AB
-can't find file: A.hs
 
+B.hs:3:5: error: Variable not in scope: z
 == Dep_Error_MD_A
-can't find file: A.hs
 
+B.hs:3:5: error: Variable not in scope: z