Cordova iOS 5.0.0 can not build without `node_modules` present because of missing `shelljs` for build phase script
See original GitHub issueBug Report
Problem
What is expected to happen?
The Cordova iOS project used to be able to build outside of a Cordova project. You could just copy platforms/ios
and then use Xcode or xcodebuild
to build your app.
What does actually happen?
You can not do that any more as the shelljs
dependency is used by one of the build step scripts and is not present without the parent node_modules
.
Information
As soon as node_modules
from the main project folder is missing (because it was either not created after a checkout from git, or because you copied over the iOS project from platforms/ios
to somewhere else, you get an error like this when trying to build with xcodebuild
or Xcode:
MacBook-Pro:ios sujan$ xcodebuild -workspace HelloCordova.xcworkspace -scheme HelloCordova -configuration Debug -sdk iphonesimulator -destination platform="iOS Simulator,name=iPhone X" build CONFIGURATION_BUILD_DIR=/Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios/build/emulator SHARED_PRECOMPS_DIR=/Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios/build/sharedpch
Build settings from command line:
CONFIGURATION_BUILD_DIR = /Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios/build/emulator
SDKROOT = iphonesimulator12.1
SHARED_PRECOMPS_DIR = /Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios/build/sharedpch
note: Using new build system
note: Planning build
note: Constructing build description
[...]
PhaseScriptExecution Copy\ www\ directory /Users/sujan/Library/Developer/Xcode/DerivedData/HelloCordova-gnnlxcyurmjjpncmcbzgevousltv/Build/Intermediates.noindex/HelloCordova.build/Debug-iphonesimulator/HelloCordova.build/Script-304B58A110DAC018002A0835.sh (in target: HelloCordova)
cd /Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios
/bin/sh -c /Users/sujan/Library/Developer/Xcode/DerivedData/HelloCordova-gnnlxcyurmjjpncmcbzgevousltv/Build/Intermediates.noindex/HelloCordova.build/Debug-iphonesimulator/HelloCordova.build/Script-304B58A110DAC018002A0835.sh
module.js:338
throw err;
^
Error: Cannot find module 'shelljs'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/sujan/Projects/throwaway/cordovaIos5Test2/platforms/ios/cordova/lib/copy-www-build-step.js:34:13)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Copy\ www\ directory /Users/sujan/Library/Developer/Xcode/DerivedData/HelloCordova-gnnlxcyurmjjpncmcbzgevousltv/Build/Intermediates.noindex/HelloCordova.build/Debug-iphonesimulator/HelloCordova.build/Script-304B58A110DAC018002A0835.sh
(1 failure)
MacBook-Pro:ios sujan$
(The error in Xcode directly is identical, as it just uses xcodebuild
under the hood.)
Known workaround
You can work around this problem by running npm install shelljs
in your iOS project. This currently seems to be the only dependency required during build.
How could this be solved?
Dependencies that are necessary for the scripts included in the project itself could/should be included in the actual project. (Alternatively there could be a package.json that is not installed by default, so it becomes at least possible to discover this when looking around)
Command or Code
cordova create testProject
cd testProject
cordova platform add cordova-ios@5.0.0
cordova build ios
# now copy the `xcodebuild` command (and add `"` around the `-destination platform=` parameter as this is missing from the command output)
cd platforms/ios
xcodebuild ... # command from before => works
rm ../../node_modules
xcodebuild ... # command from before => fails with error shown above
Environment, Platform, Device
macOS 10.14.2 (Mojave)
Version information
Cordova CLI 8.1.1, Cordova iOS 5.0.0, Xcode 10.1 (10B61)
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
I think my preference is for option 2. The script isn’t complicated, and consists mostly of shelling out to run various commands, so there’s no compelling reason in my mind for it to not just be a bash script. There’s also a lot of effort that goes into making sure it runs with the right node executable, and in theory a bash script would avoid all of that hassle.
And that is where my sleuthing ends, I am not qualified to decide if we should adapt the old .sh and just add the changes done to the .js or write a new shell script. In generall I have no idea how shell scripts work, so I am pretty lost. Can you take a shot at it please @dpogue?