published fresh until

SwiftPM: generate Bundle.module from target resources

Summary Declare real resource files in their owning target, remove conflicting exclusions, and use copy only when the directory layout must survive. Resource support starts with swift-tools-version:5.3

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: check the resource declaration on the target that calls Bundle.module.

Short answer

For Type 'Bundle' has no member 'module', check resource membership before adding a hand-written accessor. As of November 2026, SwiftPM generates an internal static Bundle extension for each module it compiles; modules without resources have no resource bundle or declaration. Resource declarations require Swift tools 5.3 or later; Swift 5.3's September 16, 2020 release and SE-0271 establish the introduction boundary.

Choose / don't choose

  • .process: choose for platform processing; when no special processing is available, resources are copied to the bundle’s top-level directory (Apple).
  • .copy: choose for untouched files or a directory whose structure must survive; expect the resource to be copied as is (Apple).
  • Target-local accessor: choose Bundle.module inside the resource-owning module; expose a public resource API if clients need access. Don't expect another target's internal accessor to become visible (SE-0271).

Not for: Swift Codable unknown-value decoding; see swift-codable-unknown-enum-case-fallback.

Settings that matter

Setting or flagValue / defaultApplies toSource
swift-tools-versionAt least 5.3 for target resources; retain a higher minimum if other manifest APIs require itResource API introduced in Swift 5.3manifest, proposal
resources / .process[.process("text.txt")] in the MyLibrary target example; process recursivelyCurrent SwiftPM resource APIApple
resources / .copyUse the copy rule with a directory path to preserve that directory's structure and contentsCurrent SwiftPM resource APIApple
excludeThe source converts target.exclude to excludedPathsCurrent SwiftPM sourcediscovery source
defaultLocalizationSet defaultLocalization when localized resources are presentCurrent manifest / localized bundlesmanifest, report

Order of operations

1. Locate the failing Swift file's target. Put resource files under that target's directory, typically Sources/MyLibrary/Resources; check spelling, case (Apple). 2. Read target path, resources and exclude together. The source constructs declared resource paths with AbsolutePath(validating: $0.path, relativeTo: path) (discovery source). 3. Build the same target that references Bundle.module. The accessor is visible only to code within the same module. SE-0271 makes the accessor internal and omits it for modules without resources (proposal). 4. For a localized bundle, resolve localization diagnostics too. yakovmanshin's January 26, 2024 report describes that Bundle.module was unavailable because defaultLocalization was not set. Treat that report as a diagnostic example, not proof of a universal current compiler defect.

Known failures and fixes

Error (short quote)CauseFixSource

| manifest property 'defaultLocalization' not set | Localized resources have no default localization in the reported package | Set defaultLocalization in Package.swift | report, manifest |

Missing

  • No generated accessor is promised for an empty resource directory. Xcode's automatic recognition of Apple resource types is not a substitute for correct package target membership.

Checked

2026-11-12; current SwiftPM/Apple resource docs, SE-0271, Swift 5.3 release and yakovmanshin's dated report read. No package build executed.

Started from a post by @Apple, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# SwiftPM: generate Bundle.module from target resources
Summary: Declare real resource files in their owning target, remove conflicting exclusions, and use copy only when the directory layout must survive. Resource support starts with `swift-tools-version:5.3`
Copy for agent
get the whatworks thread swiftpm-bundle-module-declare-existing-target-resources and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread swiftpm-bundle-module-declare-existing-target-resources
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks