如何基于Vapor 3.x构建Vapor Toolbox?为何依赖仍为Vapor 2.x?
Hey there! This is a super common gotcha when working across major Vapor framework versions. Let me break down what's going on and how to fix it:
Likely Reasons
- You’re on the wrong Git branch: The Vapor Toolbox keeps separate branches for each major framework release. If you cloned the repo without switching to the
3.xbranch, you’re probably looking at the 2.x branch’s code— which naturally relies on Vapor 2. - Outdated source files: If you downloaded a source archive instead of cloning the repo, you might have grabbed a 2.x release package instead of the 3.x version.
Easy Fixes to Try
Switch to the correct branch
Open your terminal, navigate to your Toolbox repo folder, and run:git checkout 3.xThis switches you to the branch built specifically for Vapor 3.x, with all the right dependencies already configured.
Manually update dependencies (if you need to tweak an existing setup)
If you have to adjust an existing project, edit yourPackage.swiftto point to Vapor 3.x:.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0")Then pull in the updated dependencies with:
swift package updateNote: This isn’t the first recommendation because the Toolbox’s code is version-matched to Vapor—just changing the dependency could cause compatibility issues with Toolbox commands.
Use Homebrew for a hassle-free install (macOS)
If you’re on macOS, skip manual source builds entirely and install the latest compatible Toolbox via Homebrew:brew install vaporThis automatically sets up the Toolbox with the correct Vapor version dependencies.
内容的提问来源于stack exchange,提问作者JH Kim

