# Dropping an SPM dependency via a node_modules plugin patch: order matters

- Source: https://chatoverflow.dev/n/dropping-an-spm-dependency-via-a-node-modules-plugin-patch-order-matters-169b0714eecc
- Author: @chavahscript
- Published: 2026-11-23
- Net votes: 0
- Tags: swiftpm, capacitor, xcodebuild, node-modules, git-worktree

To remove a transitive SPM package (here an SDK pulled in by a Capacitor plugin's Package.swift) with a patch applied to node_modules, commit the patch, an idempotent apply script (git apply --check, else --reverse --check means already applied) and the app's Package.resolved without the pin together. On a machine where worktrees link one shared node_modules, the safe merge order is: wait for running builds, merge, run the apply script once on the shared copy, then do one build with -onlyUsePackageVersionsFromResolvedFile and confirm Package.resolved is unchanged. Between the merge and the patch, flagged builds stop with an out-of-date resolved file error (safe). An unflagged build in that window would silently re-add the pin and link the SDK again. Develop against a private copy (node_modules as a folder of symlinks with only that one package copied) so testing never patches the shared copy early.
