NativeScript iOS运行时.pch.gch文件路径警告的解决问询
Hey there, let's tackle this warning you're hitting when running tns run ios—I've seen similar quirks with Xcode's precompiled header caching in NativeScript projects. Here's a breakdown of what's going on and how to fix it:
Why This Warning Pops Up
That .pch.gch file is Xcode's cached precompiled version of your Objective-C prefix header (appname-Prefix.pch). The warning happens because:
tns run iosuses a slightly different build workflow thantns build—it spins up a live sync session with the simulator/device, which might use a temporary or alternate build directory that wasn't used during a regularbuild.- A leftover cached file from an older build (maybe from a previous NativeScript version, or a manual Xcode build) is sitting in a path that Xcode's current security/build restrictions now flag as "outside allowed roots".
- Removing the iOS platform with
tns platform remove iosdoesn't touch Xcode's global derived data or leftover cached files outside the project'splatforms/iosdirectory, which is why that step didn't resolve it.
Do You Need to Fix It?
Short answer: Probably not, if your app runs fine. This is a harmless warning about stale cache—your app's functionality won't be impacted. That said, if you start seeing actual compilation errors (like missing header files) or want to clean up noise in your console, it's worth addressing.
Solutions to Try
Since removing the iOS platform didn't work, try these steps in order:
Clean NativeScript's project cache
Run this command in your project root to wipe local build artifacts:tns cleanThis will clear out cached build files specific to your NativeScript project, including any misaligned prefix header references.
Delete the stale
.pch.gchfile directly
Grab the full path from the warning ({pathToFile}/appname-Prefix.pch.gch) and delete it manually. Since it's a cached file, Xcode will regenerate a fresh one in the correct path on your next build/run.Clear Xcode's global derived data
Xcode stores cached build files across all projects in its Derived Data folder. To wipe this:- Open Xcode → Go to
Xcode > Settings > Locations - Click the arrow next to the Derived Data path to open the folder in Finder
- Delete the folder corresponding to your NativeScript project (or the entire Derived Data folder if you don't mind clearing all project caches)
Alternatively, run this terminal command:
rm -rf ~/Library/Developer/Xcode/DerivedData- Open Xcode → Go to
Verify your iOS build configuration
Check your project'sApp_Resources/iOS/build.xcconfigfile (if it exists) for any custom header search paths. If there are hardcoded paths pointing to old directories, update them to use relative paths or NativeScript's built-in variables.
After trying these steps, run tns run ios again—the warning should be gone.
内容的提问来源于stack exchange,提问作者Jan Willem Keizer

