question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cordova iOS 5.0.0 can not build without `node_modules` present because of missing `shelljs` for build phase script

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dpoguecommented, Feb 25, 2019

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.

0reactions
janpiocommented, Mar 1, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cordova iOS 5.0.0 can not build without `node_modules ...
Cordova iOS 5.0.0 can not build without node_modules present because of missing shelljs for build phase script #540. Closed. 3 tasks done.
Read more >
ios - cordova build error when `node cordova/lib/copy-www ...
js in Build Phases, it builds successfully, but with no page effect expected in html (Cause no www resource copied I think). and...
Read more >
Ionic package IOS Build fails missing 'xcode' npm module on ...
I run ionic package build ios --profile --release on my project ... Cannot find module '/Users/package/workspace/<my_app_dir>/cordova/ ...
Read more >
Release Notes for Cordova (iOS) - Gitea
Cordova is a static library that enables developers to include the Cordova API in their iOS application projects easily, and also create new...
Read more >
cordova-ios/RELEASENOTES.md - UNPKG
Cordova is a static library that enables developers to include the Cordova API in their iOS application projects easily, and also create new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found