SwiftUI Preview - Failed to Build Scheme, No such module "ProjectName"
Asked Answered
T

3

18

I am trying build a Preview for a project that is built on SwiftUI. At first, I created the project with the name 'VOIP'. After some development and time, I connected it to the AppStore Connect and the name of the project was created differently, Let's say VoipApp. I can build the project into simulator or a device without any problem, however when I try to preview a SwiftUI View, it says No such module VOIP at project navigator. But as I said it just happens when I try to preview.

Here is the diagnostics;

no such module \'VOIP\'

----------------------------------------

SchemeBuildError: Failed to build the scheme "VOIP"

no such module 'VOIP'

Compile /Users/myuser/Projects/VOIP/VOIPTests/VOIPTests.swift:
/Users/myuser/Projects/VOIP/VOIPTests/VOIPTests.swift:10:18: error: no such module 'VOIP'
@testable import VOIP
             ^ 

I tried some answers from the network, but neither of them have been worked.

Taxation answered 2/3, 2020 at 17:20 Comment(5)
Do you have VOIPTests.swift? Is it really import VOIP there? Did you try to remove some of those, or both? Preview uses pre-built caches heavily - did you try to force clean everything, physically, like DerivedData, etc?Tabitha
Of course I do and there is. I did try to force clean but not the derived data.Taxation
If it is there then why? Why don't remove it? You changed main app module name, so should rename it everywhere previous was used - it is not done automatically.Tabitha
I did not changed the module name, my employer created it with a different name on app store connect and when changed the team to get provisioning profiles it changed automatically. I mean my projects name still the same, which is VOIP, on my local. However I install it to simulator or a device the is as appearing as at the app store connect name.Taxation
https://mcmap.net/q/417629/-file-not-found-linker-command-failed-with-exit-code-1-in-xcode-4-5-1 this answer solved my issue. I just removed the scheme and created new one with new name.Taxation
T
51

The comment about recreating the scheme did not work for me. However, I found that I was able to change the module name to the value expected by SwiftUI by editing the "Product Module Name" setting:

enter image description here

Tuppence answered 27/5, 2020 at 23:20 Comment(3)
This was the solution for me. I have 3 different schemas and build configurations, and the SwiftUI preview stopped working once added. Setting the "Product module name" as the project name solved the problemHypoderm
This didn't solved my issue.Burd
I had various build target that all had differents names, just modifying this to have the same Product Module Name solved it for me 🍾Endocrine
S
0

I just remove the pods and add my libraries through "Package Dependencies", it's show preview.

Sato answered 23/8, 2023 at 11:44 Comment(0)
E
-2

try "Xcode > Product > Clean Build Folder"。

Ethaethan answered 18/9, 2022 at 9:27 Comment(1)
Be more explanative and make code snippet into Xcode > Product...Cybele

© 2022 - 2025 — McMap. All rights reserved.