Cannot create Swift scratch context (couldn't create a ClangImporter)

I'm getting the error "Cannot create Swift scratch context (couldn't create a ClangImporter)" when running a Swift project in XCode 12.3 on Catalina when I try to use the debugger. There is a resolution of this problem described at https://forums.raywenderlich.com/t/entering-debugger-in-swift-project-couldnt-create-a-clangimporter/130829 but I don't understand the fix of "removing zsh customisations in dotfiles". Can anyone explain what the files to change are and how they have to be changed? (I'm new to Mac development)

Replies

This problem often recurs, even with a new account and using the bash shell. Closing and re-opening Xcode seems to fix it.

I haven’t yet watched this, but I suspect that WWDC 2022 Session 110370 Debug Swift debugging with LLDB will be very helpful here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Problem has recurred and wasn't fixed by restarting Xcode. Video transcript wasn't helpful unfortunately except to indicate that lldb is very complicated and the problem is something to do with linking

  • Problem appears with iOS 12.4 simulator for iPhone 6 but does not appear using device

  • Problem appeared with device as well as simulator . Tried removing all the project-alphabeticstring folder from XCode DerivedData folder. I then had to delete and reload a Swift Package used by the project to make the project build without reporting a missing package. This fixed the problem when using the device but not when using the simulator.

I managed to get similar problem fixed, in my case the root cause was a library that was distributed in binary form and had somehow managed to put extra framework searchpaths in the library configuration. The search paths were relative to the developers computer home folder so they did not work properly. There were also some extra flags that were used for their internal debugging.

I managed to find the root cause by using swift-healthcheck on the debugger and comparing it to a version that did not have this problem.

There is not too much information about the swift-healthcheck available currently, but you can just type it in the debugger and see the output. Debug Swift with LLDB (WWDC 2022) session had some information.

Post not yet marked as solved Up vote reply of PGHM Down vote reply of PGHM