Trying to test Swift 4 using Xcode-beta (v9) on my machine and having issues with importing packages into a test project:
swift package init --type executable
Package.swift
and added 2 projects to try out:Package.swift
// swift-tools-version:4.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "sampleproject", dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), .package(url: "https://github.com/IBM-Swift/Kitura.git", from: "1.7.6"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.5.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "sampleproject", dependencies: []), ] )
swift build && swift package generate-xcodeproj
No such module Kitura/Alamofire
error messageswift build
in terminal produces the following error:Compile Swift Module 'investprosto' (1 sources) /Users/username/Projects/sampleproject/Sources/sampleproject/main.swift:1:8: error: no such module 'Kitura' import Kitura ^ error: terminated(1): /Applications/Xcode- beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift- build-tool -f /Users/username/Projects/sampleproject/.build/debug.yaml
Dependencies virtual folder contains the directories with the same package names, but they are empty. However, .build\checkouts
and .build\repositories
contain packages folders and corresponding files.
Is there something I'm missing in my system's configuration?
Turns out I had to also include the dependencies into the .target
of the Package.swift:
.target(named: "sampleproject", dependencies: ["Kitura", "Alamofire"])
and build the project again.
Even though you need to add the target
into the Package.swift
sometimes it's not enough. I have fixed the issue by deleting the .build
dir and the file Package.resolved
, then running swift build
or build from Xcode. Build command was not fetching packages as it was already in resolved
file but if you delete the .build
dir it becomes meaningless. You can verify it by checking the Dependencies
dir from Xcode it will be empty if there is error like No such package/module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With