No Such Module 'OrderedCollections'

I'm developing an input method for macOS and want to use the OrderedDictionary offered by swift-collections. I tried to add swift-collections to my project using the XCode "add packages..." interface and selected OrdredCollections to be added to "Frameworks, Libraries, and Embedded Content".

When I tried to do import OrderedCollections in my code, XCode told me that No such module 'OrderedCollections'.

I checked the build log and it seems that swift-collections is building correctly but may not be linked correctly to my code.

The full error message, including the command XCode executed is as follows:

CompileSwift normal arm64 /Users/kevin/Dev/personal/hangul_ime/Hangeul/Constants.swift (in target 'Hangeul' from project 'Hangeul')
cd /Users/kevin/Dev/personal/hangul_ime
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -c /Users/kevin/Dev/personal/hangul_ime/Hangeul/CandidatesView.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Jaso.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Jamo.swift /Users/kevin/Dev/personal/hangul_ime/Theme/ThemeConfig.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/AppDelegate.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Syllable.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/State.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/InputController.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/CandidatesWindow.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Dictionary.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/InputSource.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Debug.swift /Users/kevin/Dev/personal/hangul_ime/Hangeul/Candidates.swift -primary-file /Users/kevin/Dev/personal/hangul_ime/Hangeul/Constants.swift -emit-dependencies-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64/Constants.d -emit-reference-dependencies-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64/Constants.swiftdeps -serialize-diagnostics-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64/Constants.dia -emit-localized-strings -emit-localized-strings-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64 -target arm64-apple-macos11.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -I /Library/Input\ Methods -F /Library/Input\ Methods/PackageFrameworks -F /Library/Input\ Methods -no-color-diagnostics -enable-testing -g -module-cache-path /Users/kevin/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -D DEBUG -serialize-debugging-options -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/kevin/Dev/personal/hangul_ime -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Hangeul-generated-files.hmap -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Hangeul-own-target-headers.hmap -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Hangeul-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Hangeul-project-headers.hmap -Xcc -I/Library/Input\ Methods/include -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/DerivedSources-normal/arm64 -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/DerivedSources/arm64 -Xcc -I/Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/DerivedSources -Xcc -DDEBUG=1 -module-name Hangeul -frontend-parseable-output -disable-clang-spi -target-sdk-version 12.3 -o /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Build/Intermediates.noindex/Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64/Constants.o -index-unit-output-path /Hangeul.build/Debug/Hangeul.build/Objects-normal/arm64/Constants.o -index-store-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-gzgkogxcpweuuabvlgficpqldcrc/Index.noindex/DataStore -index-system-modules

/Users/kevin/Dev/personal/hangul_ime/Hangeul/InputController.swift:3:8: error: no such module 'OrderedCollections'
import OrderedCollections

System

XCode 14.0.1
macOS Ventura 13.0
Apple M1 Max

Did you add it to your target? I just tried it and it worked for me.

Screenshot 2022-10-27 at 4.28.47 pm

I did add OrderedCollections to my target.

I created a branch on my repo with a reproduction of the error. I think there might be something wrong with my project configs.However, I can't find anything suspicious even after comparing my configs with other open source input methods. If you build that project, you should be able to reproduce the No Such Module error.

I just realized my project is 380MB with the data included so I created a minimal project to show the error: GitHub - AlienKevin/sample_imkit_no_such_module: A sample IM Kit project to reproduce a no such module error

The first time you build the project, it may show something like packages are not supported in legacy mode. You can just go to File -> Project Setup -> Advanced and select XCode default. After that, if you restart XCode and build the project again, you will see the No Such Module error.

I think your Xcode project got borked somehow.

I got the minimal project to build* by removing the references to the package in the project 'package dependencies' page and the target 'General/Frameworks' section, then re-adding the package via right clicking the files pane on the left and using the 'Add Package...' menu item.

That way the package turns up in the sidebar.

  • well, it didn't actually build, it gave an error error build: mkdir(/Library/Input Methods/PackageFrameworks, S_IRWXU | S_IRWXG | S_IRWXO): Permission denied (13) . But that's not relevant to your question.
1 Like

Original Issue Resolved

Thanks for your replies. I found the root cause of the problem is actually due to the use of custom build path instead of Xcode default build path. Basically, I changed two properties in the Build Settings of my target which caused the issue:

  1. Set Build Products Path to /Library/Input Methods instead of keeping the default path build
  2. Added a CONFIGURATION_BUILD_DIR variable in the User-Defined section of the Build Settings

These changes apparently are not compatable with the swift package manager and the swift-collections library is not linked properly with my code. The solution is to:

  1. Keep the Build Products Path as the default path build.
  2. Remove the CONFIGURATION_BUILD_DIR variable from the User-Defined section.
  3. Set the Installation Directory under Deployment to /Library/Input Methods.
  4. Add a Copy Files build phase to Build Phrases which copies the built binary, in my case Hangeul.app, from the build/Debug directory to /Library/Input Methods.

New Issue

After these steps, the issue is resolved. However, I got this annoying error everytime I build the project if there are code changes:

ValidateEmbeddedBinary /Library/Input\ Methods/Hangeul.app (in target 'Hangeul' from project 'Hangeul')
    cd /Users/kevin/Dev/personal/hangul_ime
    /Applications/Xcode.app/Contents/Developer/usr/bin/embeddedBinaryValidationUtility /Library/Input\ Methods/Hangeul.app -signing-cert 2789WEIOW1DFIEWOPICX20289WE -info-plist-path /Users/kevin/Library/Developer/Xcode/DerivedData/Hangeul-vcxkowreaiufvhpsudzfofewa/Build/Products/Debug/Hangeul.app/Contents/Info.plist

error: Embedded binary is not signed with the same certificate as the parent app. Verify the embedded binary target's code sign settings match the parent app's.

		Embedded Binary Signing Certificate:	Not Code Signed
		Parent App Signing Certificate:		Apple Development: Kevin (5G6F3GXYS)

What's confusing me is that my target's code sign settings are identical to that of the parent app's, so the error message's suggestion is not relevant. Since new users can only upload one media, I'm only showing the parent's code sign settings. However, the target's is identical to that of the parent's.

Parent App's Code Sign Settings

I found a workaround which involves manually deleting the Hangeul.app in my /Library/Input Methods and build the project again. This usually solves the binary not signed with the same certificate issue but I'd like to know the root cause of this code sign issue.