Ionic Pro - Package Build fails due to git submodule

It simply skip git submodule setup. Because this, it does not pull out the source code in git submodule and fails to build.

Can any one help please?

Running with gitlab-ci-multi-runner 9.1.0 (0118d89)
  on ip-10-2-214-40 (f537d27d)
Using Shell executor...
Running on ip-10-2-214-40...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/f537d27d/1/thruthesky/philgo-chat'...
Checking out b0b4c52b as master...
Skipping Git submodules setup
$ run "fetch-updates"
Running Stage fetch-updates for Job: 6103900
Checking for build process updates...
$ run "build-android"
Running Stage build-android for Job: 6103900
Parsing ionic.config.json for project settings

While deploy build success with same project and same submodules.

Updating/initializing submodules...
Synchronizing submodule url for 'src/app/modules/...'
Synchronizing submodule url for 'src/app/modules/...'
   e8c5cfe..2ff8703  master     -> origin/master
Submodule path 'src/app/modules/...': checked out '2ff870321bd2abf40ea43cdd3ad0c61fdd710f1d'

As indicated in this Zendesk issue, Submodules are supported now, but only for public repos with no authorization required.

One option suggested in othersimilar issues is to switch from submodules to subtrees.

Finally, if it’s not an option, here is a bash script I came up with as a workaround. I still want to support submodules in my original private repo on Bitbucket, but I don’t care how it is stored on Ionic Pro. So I just create a new temporal branch, copy submodule and include it as a simple directory in the source code. Then I remove .gitmodules file and push the changes to ionic origin. Then I delete the local branch and clean up.

Here is the code that you can save as a shell script and run it each time instead of git push ionic HEAD. But first of all, consider switching to subtrees :slight_smile:


# Prepare repository and push to Ionic Pro
# - checkout a new branch
# - copy submodule to another directory, update its alias in tsconfig.json and commit
#   (we need it because Ionic Pro does not support private submodules yet)
# - push to Ionic Pro and clean up (switch to original branch and delete the new one)

now=$(date +"%m/%d/%Y %H:%M")
original_branch=$(git symbolic-ref --short HEAD)
branch_id=$(date +"%m%d%Y-%H%M%S")
commit_msg="Copied submodule for Ionic Pro ($now)"

set -e # exit script if any command fails

printf "Preparing repository for Ionic Pro...\n"

if [ `git branch --list $tmp_branch` ]
  printf "  - branch $tmp_branch already exists, deleting it\n"
  git branch -D ${tmp_branch}

printf "  - checking out a new branch $tmp_branch\n"
git checkout -b ${tmp_branch}

printf "  - copying $submodule_dir into $target_dir\n"
cp -r ${submodule_dir} ${target_dir}

printf "  - removing .git directory from the copy\n"
rm -rf ${target_dir}/.git

# this is optional, only if you use TS alias for your submodule! The regex should be updated for your needs
printf "  - replacing @my-submodule alias in tsconfig.json\n"
sed -i "s_\.\.\/${submodule_dir}\/_\.\.\/${target_dir}\/_g" tsconfig.json

printf "  - removing .gitmodules file"
git rm .gitmodules

printf "\nSubmitting...\n"
printf "  - adding changes to git\n"
git add ${target_dir} tsconfig.json

printf "  - committing changes\n"
git commit -m "$commit_msg" > /dev/null

printf "  - pushing changes\n"
git push ${ionic_origin} ${tmp_branch}

printf "\nCleaning up...\n"
printf "  - checking out $original_branch\n"
git checkout ${original_branch} > /dev/null

printf "  - deleting branch $tmp_branch\n"
git branch -D $tmp_branch

printf "\nDone!\n"
printf "  now you can go to Ionic Pro dashboard and build a package for commit with this message:\n    \"$commit_msg\"\n\n"

Sorry for bumping this thread.

Does the script still work for you @whizai? I’m also using it and eventhough .gitmodules gets removed (I checked), the web build still fails on submodules, any idea?

Updating/initializing submodules...
fatal: No url found for submodule path 'XXX' in .gitmodules
ERROR: Job failed: command terminated with exit code 1

PS: Sed command on OSX is a bit different so I changed that line in your script to this, if anyone else is looking to get it to work on OSX

sed -i '' 's|${submodule_dir}|${target_dir}|' tsconfig.json

Yes, my script still works for me.
If you see the script completes successfully and you are sure you select correct commit (last one) for build on Ionic Pro, then you should debug the script. Comment out everything from “pushing changes” and below and play around with it. You can comment more steps, execute the script and see what’s actually going on on every step.
The issue may be anything: wrong relative paths (I’m running my script from the project root with “npm run ionic-pro:push”, where “ionic-pro:push” is a script in package.json that executes this script file), incorrect variables initialization in the beginning of the file. Also, I’m using only one submodule; this scrip will not work with more than one submodule

Oh, and check your build process. Build for iOS is executed from “build” script in package.json. Make sure you are not trying to initialize submodules in that script. I guess Ionic Pro runs submodule initialization when it sees “.gitmodules” file in the project root. It indicates that “.gitmodules” does not get removed, at least the removal is not pushed to the Ionic Pro repo.

I manually ran and tested the script and everything works fine (with commenting out step by step). I will investigate further with your tips. Thanks for your fast reply.

Good news! Seems like private sub-modules are working now!

I set up integration with my main repository on Bitbucket Cloud ( and now private sub-module is successfully fetched during the build

UPD: it’s not that simple; see messages below


That sounds great, gonna try it out. Thanks @whizai

@Ben_c, sorry for misguiding you. Now private sub-modules work pretty well with Web Builds - and that made me happy. But then I realized it still does not work with package builds. During package build I still see the message about skipping sub-modules step.
It seems strange, so I raised a ticket for Ionic support. Waiting for their response. Will let you know

Now it’s working, they did a small update and private sub-modules really work for package builds.


1 Like

Hello, I have one question. Can you help me ? ionic 4 platforms / browser / www when I moved it to the server, and I’m doing a reload. I see that “cannot get page”. But navigation worked.