Amplify-ios: New iOS project build failure

Created on 5 Mar 2020  路  17Comments  路  Source: aws-amplify/amplify-ios

Describe the bug
Following along with Amplify iOS Getting Started after creating the workspace and attempting to build it is failing on PhaseScriptExecution.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new single view Swift project (storyboard)
  2. Create a Podfile following the steps in the tutorial Step 1
  3. Install the pods: pod install --repo-update
  4. Open the new workspace and attempt to build
  5. Get the following error:
    ```...
    /bin/sh -c /Users/username/Library/Developer/Xcode/DerivedData/AmplifyPrac-bealbahytjoipvfcoytbyzyythmp/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/amplify-tools.build/Script-A25A17163ECF22B928D19C9FEBC62DAB.sh

/Users/username/Library/Developer/Xcode/DerivedData/AmplifyPrac-bealbahytjoipvfcoytbyzyythmp/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/amplify-tools.build/Script-A25A17163ECF22B928D19C9FEBC62DAB.sh: line 3: npm: command not found
warning: Node is not installed. Vist https://nodejs.org/en/download/ to install it
/Users/username/Library/Developer/Xcode/DerivedData/AmplifyPrac-bealbahytjoipvfcoytbyzyythmp/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/amplify-tools.build/Script-A25A17163ECF22B928D19C9FEBC62DAB.sh: line 18: amplifyxc.config: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

It is also giving the mistaking warning that node was not found.

% which node
/Users/username/.nvm/versions/node/v12.16.0/bin/node
% node --version
v12.16.0

% which npm
/Users/username/.nvm/versions/node/v12.16.0/bin/npm
% npm --version
6.13.4
```

Expected behavior
Building the project should result in a successful build and the 3 files the tutorial talks about should be generated.

Environment(please complete the following information):

  • Amplify Framework Version: 4.14.1 (amplify --version)
  • Dependency Manager: Cocoapods
  • Swift Version : 5.1.3 (swift --version)
  • Xcode Version: Version 11.3.1 (11C504)

Device Information (please complete the following information):

  • Device: iPhone11, Simulator 11, 11 Pro
  • iOS Version: iOS 13
  • Specific to simulators: No simulators and real device is effected.
dev tools

Most helpful comment

@detectedstealth @buffpojken This is an issue when using zsh as the default shell. As a workaround, you can run npx amplify-app --platform ios in the root of the project and the rest of the steps in the documentation should work as expected.

All 17 comments

@detectedstealth me too as well

@detectedstealth what shell are you using and what do you use to configure it? (e.g. .bash_profile, .bashrc, .zshrc, ...)

@nikhname I used .zshrc to configure things. Here is the contents of the file:

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Same here. Samt config as above.

@detectedstealth @buffpojken This is an issue when using zsh as the default shell. As a workaround, you can run npx amplify-app --platform ios in the root of the project and the rest of the steps in the documentation should work as expected.

Thanks, that worked just fine!

That worked to generate the files thanks @buffpojken

I spoke to soon, the first build worked but as soon as I set modelgen=true I am encountering the same error.

/Users/username/Library/Developer/Xcode/DerivedData/AmplifyPrac-bealbahytjoipvfcoytbyzyythmp/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/amplify-tools.build/Script-A25A17163ECF22B928D19C9FEBC62DAB.sh: line 3: npm: command not found
warning: Node is not installed. Vist https://nodejs.org/en/download/ to install it
/Users/username/Library/Developer/Xcode/DerivedData/AmplifyPrac-bealbahytjoipvfcoytbyzyythmp/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/amplify-tools.build/Script-A25A17163ECF22B928D19C9FEBC62DAB.sh: line 28: amplify: command not found
Command PhaseScriptExecution failed with a nonzero exit code

Do I need to run the command you suggested every time I make a change? @buffpojken

@detectedstealth is the file amplifyxc.config present in the root of your project after running that command?

@nikhname yes the file is present in the root of my project. When setting modelgen=false things compile, when set to true the amplify-tools framework fails to build with the above error. It's complaining once again that amplify command was not found. As far as I know zsh is the default shell in Catalina+ so this issue definitely needs to be resolved some how.

https://support.apple.com/en-us/HT208050

Hmm, it worked just fine for me running it once - then all workflows hitherto (generating models, pushing, tested adding DataStore) worked just fine.

@buffpojken what were the exact steps you took? For me this morning:

  1. Create a new Xcode project
  2. Init the pod
  3. Installed the pods
  4. Ran the command you suggested which generated the files.
  5. Opened the workspace built fine
  6. Updated modelgen=true
  7. Tried to build and it failed
  8. Cleaned the projects tried to build again failed.
  9. Changed modelgen=false, cleaned the project and build worked.

I have deactivated nvm and installed node/amplify globally and I can build. I'll leave it like this for now but kind of annoying I can't use NVM. Seems like as people said this is an issue how Xcode uses and non-interactive shell the build script might need to be updated to source .zshrc/.bashrc if they exist instead of depending on the globals etc..

Also it seems that named profiles are also not supported:

init failed
Error: Profile configuration is missing for: default
    at Object.getProfiledAwsConfig (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/system-config-manager.js:82:11)
    at Object.getAwsConfig (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/configuration-manager.js:638:45)
    at Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/initializer.js:23:50)
Command PhaseScriptExecution failed with a nonzero exit code

I had a custom named profile I was using for this which I setup using amplify configure however the framework scripts for some reason require the default profile.

@detectedstealth yes this is an issue with nvm not being loaded through Xcode's non-interactive shell.

As for the named profile, please update profile in amplifyxc.config to your desired named profile if default is not configured.

We will look into ways to loading different shell profiles through Xcode as well as updating the docs to make this flow clearer.

@nikhname thanks that solves the profile issue I had.

It sounds like this can be closed, feel free to re-open if not, or open a new issue if seeing a different problem

Was this page helpful?
0 / 5 - 0 ratings