Generating resource_bundle_accessor, Type 'Bundle' has no member 'module'

SPM generates the resource_bundle_accessor only if the corresponding target contains resources as the argument like:

    .target(
        name: "ChenzookKit",
        dependencies: ["Apollo"],
        resources: [.process("Resources")] // <- `copy` or `process` doesn't really matter 
    ),

Also, note that it should be a valid resource path.

AND❗️

The project MUST actaully contains Resources inside the target's Directory!

Example

AND❗️❗️

Don't forget to build (cmd+b) the code to make the .module be created!


If you see errors like this:

Error: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target

Type 'Bundle' has no member 'module'

Then review the following five conditions:

1. Check that the first line of your Package.swift declares the use of swift-tools-version:5.3 or a later version.

// swift-tools-version:5.3

2. Check the Resource folder is under the target folder. For instance,

Sources/MyTarget/Resources
Tests/MyTargetTests/Resources

3. Check that you already added at least one resource. For instance,

Tests/MyTargetTests/Resources/paginatedLabels.json

4. Check that you open the package by opening the file Package.swift with Xcode.

5. Check that the Package.swift file declares a resources element, like this:

.testTarget(
    name: "MyTargetTests",
    dependencies: ["MyTarget"],
    resources: [
        .process("Resources")
    ]
),

At this point, the compiler synthesized a file resource_bundle_accessor.swift with this content:

extension Foundation.Bundle {
    static var module: Bundle = {
...

To check that the file was indeed synthesized:

# is the bundle being synthesized when you build?
find ~/Library/Developer/Xcode/DerivedData* -iname resource_bundle_accessor.swift

To load resources from the package bundle use Bundle.module, e.g.

UIImage(named: "share", in: Bundle.module, compatibleWith: nil)

To find the path to the package bundle directory:

MODULE=MyModuleName && find -E ~/Library/Developer/Xcode/DerivedData -regex ".*$MODULE_$MODULE.bundle"

To check that the package bundle contains a particular resource, e.g. an image:

# I’m building for iPhone 12 (@3x). Is [email protected] inside the bundle?
find ~/Library/Developer/Xcode/DerivedData* -iname Assets.car -exec xcrun --sdk iphoneos assetutil --info {} \; | grep -E "share.*png"

Here is an example that uses custom directories:

targets: [
    .target(
        name: "Kit",
        dependencies: [],
        path: "sources/main",
        resources: [
            .process("resources")
        ]
    ),

where directories are:

Kit/
├── sources/
│   └── main/
│       ├── SourceFile.swift
│       └── resources/
│           └── file.json
└── Package.swift

If everything fails and you suspect a bug check the bug database for SPM.