alionthego
alionthego

Reputation: 9733

"warning: no targets to build in package" error in swift package manager

I am trying to install SocketIO into my swift 4 iOS project using the swift package manager. The Package.swift file looks like this:

// 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: "MyApp",

    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMajor(from: "12.0.0"))
    ]

)

On command line when I type 'swift build' the packages are fetched but there is an error:

"warning: no targets to build in package"

When I try to import SocketIO in my app I get:

"No such module 'SocketIO'" error.

This is my first time using Package Manager. Just wondering how to resolve this and whether or not I need to add targets myself in the Package.swift file?

Not sure if I set up Package Manager correctly initially. Also wondering if there is a way to uninstall and reinstall Package Manger? Or is it just a matter of replacing the Package.swift file in the project directory.

Upvotes: 4

Views: 2321

Answers (2)

Alex Motor
Alex Motor

Reputation: 1821

I had the same issue.

I found documentation for SPM v4.

By this link

So, you should try this:

// 1.0.0 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.0.0"),

// 1.2.0 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.2.0"),

// 1.5.8 ..< 2.0.0
.package(url: "/SwiftyJSON", from: "1.5.8"),

// 1.5.8 ..< 2.0.0
.package(url: "/SwiftyJSON", .upToNextMajor(from: "1.5.8")),

// 1.5.8 ..< 1.6.0
.package(url: "/SwiftyJSON", .upToNextMinor(from: "1.5.8")),

// 1.5.8
.package(url: "/SwiftyJSON", .exact("1.5.8")),

// Constraint to an arbitrary open range.
.package(url: "/SwiftyJSON", "1.2.3"..<"1.2.6"),

// Constraint to an arbitrary closed range.
.package(url: "/SwiftyJSON", "1.2.3"..."1.2.8"),

// Branch and revision.
.package(url: "/SwiftyJSON", .branch("develop")),
.package(url: "/SwiftyJSON", .revision("e74b07278b926c9ec6f9643455ea00d1ce04a021"))

Upvotes: 0

user1046037
user1046037

Reputation: 17695

Could you try the following:

  • Use .Package instead of .package
  • Use majorVersion: 12, minor: 0 instead of .upToNextMajor

Code:

import PackageDescription

 let package = Package (
    name: "MyApp",
    dependencies: [
       .Package(url: "https://github.com/socketio/socket.io-client-swift", majorVersion: 12, minor: 0)
    ]
)

Output:

If successfully built the following will be created:

  • Package.resolved will contain the packages used
  • .build hidden directory is created, these will contain the build files.

Tested on:

  • Swift 4.0

Refer:

https://swift.org/getting-started/#using-the-package-manager

Upvotes: 1

Related Questions