swift-package-manager: [SR-15876] Unhelpful error: Could not build Objective-C module ‘ModuleName’

Previous ID SR-15876
Radar rdar://89082987
Original Reporter @ahoppen
Type Bug
Additional Detail from JIRA
Votes 2
Component/s SourceKit-LSP
Labels Bug
Assignee None
Priority Medium

md5: 9ddcee184f7c88e97c4a2a1e791ed8aa

Issue Description:

From https://forums.swift.org/t/unhelpful-error-could-not-build-objective-c-module-modulename/55381

Sometimes when loading a package into the VSCode extension the SourceKit-LSP server will return the error

Could not build Objective-C module 'ModuleName'

where ModuleName is the name of some module being imported. This error appears on modules regardless of whether they include any Objective-C or not. Unfortunately I haven’t found a consistent way to replicate this error. It appears to disappear if you build the project and restart VSCode. If it is related to the relevant module not being built it is not a very helpful message.

In what situations is this error message meant to appear.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 23 (11 by maintainers)

Most upvoted comments

Getting the same issue here from Neovim using it’s built-in lsp client

How is that warning (at least a warning, please!) not on by default??

Thanks a lot. I was able to reproduce the problem now. Since this reproducer doesn’t involve SourceKit-LSP, I’m moving it over to SwiftPM.

This script reproduces the issue locally for me

cd /tmp
rm -rf package-benchmark

set -x

git clone https://github.com/ordo-one/package-benchmark
cd package-benchmark
git checkout 0.3.2
echo "import BenchmarkSupport" > Tests/BenchmarkTests/BenchmarkTests.swift
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-11-19-a.xctoolchain/usr/bin/swift test
Output
+ git clone https://github.com/ordo-one/package-benchmark
Cloning into 'package-benchmark'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (299/299), done.
remote: Compressing objects: 100% (204/204), done.
remote: Total 310 (delta 146), reused 180 (delta 74), pack-reused 11
Receiving objects: 100% (310/310), 120.45 KiB | 613.00 KiB/s, done.
Resolving deltas: 100% (146/146), done.
+ cd package-benchmark
+ git checkout 0.3.2
Note: switching to '0.3.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 438adfb Initial commit
+ echo 'import BenchmarkSupport'
+ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-11-19-a.xctoolchain/usr/bin/swift test
Fetching https://github.com/apple/swift-argument-parser from cache
Fetching https://github.com/apple/swift-numerics from cache
Fetching https://github.com/ordo-one/package-jemalloc from cache
Fetched https://github.com/ordo-one/package-jemalloc (0.43s)
Fetching https://github.com/swift-extras/swift-extras-json from cache
Fetched https://github.com/apple/swift-numerics (0.45s)
Fetching https://github.com/apple/swift-system from cache
Fetched https://github.com/apple/swift-argument-parser (0.56s)
Fetching https://github.com/ordo-one/TextTable from cache
Fetched https://github.com/swift-extras/swift-extras-json (0.40s)
Fetched https://github.com/apple/swift-system (0.40s)
Fetched https://github.com/ordo-one/TextTable (0.38s)
Computing version for https://github.com/ordo-one/package-jemalloc
Computed https://github.com/ordo-one/package-jemalloc at 1.0.0 (0.05s)
Computing version for https://github.com/ordo-one/TextTable
Computed https://github.com/ordo-one/TextTable at 0.0.1 (0.05s)
Computing version for https://github.com/swift-extras/swift-extras-json
Computed https://github.com/swift-extras/swift-extras-json at 0.6.0 (0.05s)
Computing version for https://github.com/apple/swift-numerics
Computed https://github.com/apple/swift-numerics at 1.0.2 (0.05s)
Computing version for https://github.com/apple/swift-argument-parser
Computed https://github.com/apple/swift-argument-parser at 1.1.4 (0.07s)
Computing version for https://github.com/apple/swift-system
Computed https://github.com/apple/swift-system at 1.2.1 (0.05s)
Creating working copy for https://github.com/ordo-one/TextTable
Working copy of https://github.com/ordo-one/TextTable resolved at 0.0.1
Creating working copy for https://github.com/apple/swift-argument-parser
Working copy of https://github.com/apple/swift-argument-parser resolved at 1.1.4
Creating working copy for https://github.com/ordo-one/package-jemalloc
Working copy of https://github.com/ordo-one/package-jemalloc resolved at 1.0.0
Creating working copy for https://github.com/apple/swift-numerics
Working copy of https://github.com/apple/swift-numerics resolved at 1.0.2
Creating working copy for https://github.com/apple/swift-system
Working copy of https://github.com/apple/swift-system resolved at 1.2.1
Creating working copy for https://github.com/swift-extras/swift-extras-json
Working copy of https://github.com/swift-extras/swift-extras-json resolved at 0.6.0
Building for debugging...
/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/module.modulemap:2:12: error: header '/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/BenchmarkSupport-Swift.h' not found
    header "/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/BenchmarkSupport-Swift.h"
           ^
/private/tmp/package-benchmark/Tests/BenchmarkTests/BenchmarkTests.swift:1:8: error: could not build Objective-C module 'BenchmarkSupport'
import BenchmarkSupport
       ^
/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/module.modulemap:2:12: error: header '/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/BenchmarkSupport-Swift.h' not found
    header "/private/tmp/package-benchmark/.build/x86_64-apple-macosx/debug/BenchmarkSupport.build/BenchmarkSupport-Swift.h"
           ^
/private/tmp/package-benchmark/Tests/BenchmarkTests/BenchmarkTests.swift:1:8: error: could not build Objective-C module 'BenchmarkSupport'
import BenchmarkSupport
       ^
[15/72] Compiling RealModule Float+Real.swift
error: fatalError