`Error creating target Swift AST context: (null)` in REPL

坚强是说给别人听的谎言 提交于 2020-01-01 04:33:05

问题


I've seen several (well, not that many, but a few) questions here on SO dealing with this error, but none of the proposed solutions worked for me. This is what I get

$ swift
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
warning: Swift error in module repl_swift: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module dyld: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreFoundation: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

...

warning: Swift error in module ServiceManagement: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libxslt.1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

error: Error creating target Swift AST context: (null)

This may or may not have happened after I issued some command that I don't remember (and my bash history does not help very much). The odd thing is that if I uninstall Xcode, the REPL starts working correctly. If I re-install Xcode, however, the errors come back. I'm on Xcode 7.2.1 (7C1002), by the way. Thoughts?


回答1:


To see your current Xcode path:

xcode-select -p

Mine was an old path:

/Applications/Xcode.app/Contents/Developer

Then update this path via:

sudo xcode-select -s /Library/Developer/CommandLineTools



来源:https://stackoverflow.com/questions/35438851/error-creating-target-swift-ast-context-null-in-repl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!