Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosting - Creating a nested amplify project is not supported #10832

Open
5 tasks done
chris-mds opened this issue Aug 2, 2022 · 31 comments
Open
5 tasks done

Hosting - Creating a nested amplify project is not supported #10832

chris-mds opened this issue Aug 2, 2022 · 31 comments
Assignees
Labels
documentation Add or update documentation hosting Issues tied to hosting category platform Issues tied to the general CLI platform

Comments

@chris-mds
Copy link

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

16.10.0

Amplify CLI Version

7.6.7

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

no

Amplify Categories

hosting

Amplify Commands

Not applicable

Describe the bug

Since today our hosting CI/CD crashes when building the backend with the error message:
Creating a nested amplify project is not supported. Project root detected: /codebuild/output/srcxxxxxxx/src/xxxxxx
Because the only change from our successful build was a little bit of frontend code, we already thought that this bug cant be due to our latest change, so for testing we rolled back to the last successful build, but the error still occurs.

Any ideas?

Expected behavior

CI/CD pipeline should build it like normal

Reproduction steps

Redeploy a version in CI/CD pipeline

GraphQL schema(s)

# Put schemas below this line

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

@josefaidt josefaidt added platform Issues tied to the general CLI platform pending-triage Issue is pending triage labels Aug 2, 2022
@josefaidt
Copy link
Contributor

Hey @chris-mds 👋 thanks for raising this! Based on the repo I have a few follow-up questions:

  • I see Amplify CLI version 7.6.7 is reported here, is this also the version used in Amplify Hosting? (by default Hosting will use latest)
  • can you provide a minimal reproduction for this issue?
  • looking at this path /codebuild/output/srcxxxxxxx/src/xxxxxx, did anything change in the buildspec (amplify.yml) that would cause the root path to be duplicated?

@josefaidt josefaidt added the pending-response Issue is pending response from the issue author label Aug 2, 2022
@chris-mds
Copy link
Author

Hey @josefaidt,

Thank you for your help. Indeed we forgot to set the amplify build to our version and it was set to latest. After downgrading to our version it works again. Maybe this case might still be of interest to you.

BR Chris

@foobarnes
Copy link

I am also getting this error on the latest CLI version. Should I open a new issue or reopen this one?

No changes to amplify.yml in the last 24 hours.

  • npm i -g @aws-amplify/cli
  • Node 16.14.2
  • Amplify CLI 9.2.0
  • Mac

@bkmulusew
Copy link

bkmulusew commented Aug 3, 2022

I'm facing the same problems too. There seems to be a problem with the new CLI version.

@lazpavel
Copy link
Contributor

lazpavel commented Aug 8, 2022

Hi @foobarnes, @bkmulusew can you check the path printed in the error message after Project root detected: and look for an amplify directory in that path? If exists it might be that at some point an attempt was made to initialize an amplify project in the path printed in the error message? Can you remove/rename that amplify directory and retry the amplify init command?

@nick-0101
Copy link

nick-0101 commented Aug 14, 2022

Getting this problem too when running amplify init inside a blank directory

@jeffearthx
Copy link

@lazpavel I am having the same issue. It appears to be related to your commit #10744 .

I am using an Nx Monorepo with the following amplify.yml.

version: 1
applications:
  - appRoot: apps/earthxapp
      backend:
        phases:
          build:
            commands:
              - amplifyPush --simple
      frontend:
        phases:
          preBuild:
            commands:
              - npm config set @gsap:registry https://npm.greensock.com/
              - npm config set //npm.greensock.com/:_authToken=XXXXXXXXXXXXXXXX
              - npm ci
              - amplify pull -y
          build:
            commands:
              - npx nx build --prod
      artifacts:
        baseDirectory: ../../dist/apps/earthxapp
          files:
            - '**/*'

The error I am getting is:

Creating a nested amplify project is not supported. Project root detected: /codebuild/output/src098391460/src/earthx
2022-08-16T05:09:10.815Z [INFO]: Error: Creating a nested amplify project is not supported. Project root detected: /codebuild/output/src098391460/src/earthx
                                 at checkForNestedProject (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/helpers/projectUtils.js:9:15)
                                 at Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/pull.js:69:50)
                                 at Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:292:29)
                                 at processTicksAndRejections (internal/process/task_queues.js:95:5)
                                 at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:64:3)
                                 at Function.runMain (pkg/prelude/bootstrap.js:1848:13)
                                 at internal/main/run_main_module.js:17:47
                                 at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
                                 at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
                                 at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:165:13)

It appears someone else is also having this issue when using a monorepo. See #2908

Does this commit break Monorepos, or am I doing something wrong?

Thanks

@lazpavel
Copy link
Contributor

Hi @jeffearthx, is the amplify pull -y the command that is causing the issue? can you get the output of pwd where the amplify pull -y command is executed?

@lazpavel lazpavel reopened this Aug 16, 2022
@jeffearthx
Copy link

Hi @lazpavel , This is happening in the backend during the "amplifyPush --simple" command. I modified my amplify,yml file to run pwd before and after the "amplifyPush --simple" script.

version: 1
applications:
    -   appRoot: apps/earthxapp
        backend:
            phases:
                build:
                    commands:
                        - pwd
                        - amplifyPush --simple
                        - pwd
        frontend:
            phases:
                preBuild:
                    commands:
                        - npm config set @gsap:registry https://npm.greensock.com/
                        - npm config set //npm.greensock.com/:_authToken=XXXXXXXXXXXX
                        - npm ci
                        - amplify pull -y
                build:
                    commands:
                        - npx nx build --prod
            artifacts:
                baseDirectory: ../../dist/apps/earthxapp
                files:
                    - '**/*'

The output in the AWS Amplify console is:

Screen Shot 2022-08-16 at 10 54 53 AM

I think "earthx/apps/earthxapp" should be correct for the Nx Monorepo setup. "aws-exports.js" gets placed in "apps/earthxapp/src" on my system.

My "amplify/.config/project-config.json" file contains:

{
  "providers": [
    "awscloudformation"
  ],
  "projectName": "earthx",
  "version": "3.1",
  "frontend": "javascript",
  "javascript": {
    "framework": "angular",
    "config": {
      "SourceDir": "apps/earthxapp/src",
      "DistributionDir": "dist/apps/earthxapp",
      "BuildCommand": "nx build --prod",
      "StartCommand": "nx serve"
    }
  }
}

Note that if I change the following Environment variable in the AWS Amplify console from (latest):

Screen Shot 2022-08-16 at 11 07 37 AM

to (9.1.0):

Screen Shot 2022-08-16 at 11 09 31 AM

Then everything compiles and deploys correctly.

Thanks for looking into this.

@lazpavel
Copy link
Contributor

I am trying to understand your folder structure, it looks that the amplifyPush --simple which triggers the Running amplify pull to generate aws-exports.js file for frontend is executed in the /codebuild/output/src098391460/src/earthx/apps/earthxapp but we detect an amplify project initialized in /codebuild/output/src098391460/src/earthx/ (this one contains the amplify directory and amplify/.config).
This is prevented in the >9.2.0 versions as it was creating a nested copy of the amplify project in the /codebuild/output/src098391460/src/earthx/apps/earthxapp. Please send us an email at [email protected] and reference this ticket so I can schedule a call, I would like to better understand your case before I can tell if this is a bug or a configuration issue. Thank you

@NickEast12
Copy link

NickEast12 commented Aug 17, 2022

Just an FYI I was running 9.2.1 and having this issue, I downgraded to my colleagues version at 9.1.0 and it worked

@amorimrafael
Copy link

@NickEast12 it worked for me. For any reason the amplify version 9.2.1 broken for me...

thanks

@brianlenz
Copy link

brianlenz commented Aug 24, 2022

We experienced the same issue in trying to set up front end hosting (Next.js) for our existing backend. We have a monorepo with the appRoot set to web in the amplify.yml file.

Downgrading Amplify CLI to 9.1.0 worked around this error for us, too 👍

@agilxpgeoffrey
Copy link

Same issue for me. Downgrading to 9.1.0 solved it.

@gcmerz
Copy link

gcmerz commented Sep 9, 2022

Wanted to +1 here. Also was trying to set up front end hosting for our existing backend. Downgrading to 9.1.0 solved this issue.

@AndresCreator
Copy link

For me the mistake was that for some reason I had different appIds from the project. Steps to solve

  1. Delete team-provider-info.json
  2. Get the appid of amplify project
  3. amplify init --appId [id]

@josefaidt josefaidt added documentation Add or update documentation and removed pending-response Issue is pending response from the issue author pending-triage Issue is pending triage labels Sep 14, 2022
@josefaidt
Copy link
Contributor

Hey folks 👋 I've marked this as a documentation issue to improve the Hosting docs for monorepos. From your feedback here, it has become clear that the monorepo support with the buildspec amplify.yml file is confusing in that the appRoot is where amplifyPush --simple will run, which expects an amplify/ directory in that root.

|- my-project/
|-- apps/
|--- my-react-app/
|---- amplify/
|---- package.json
|--- my-svelte-app/

@brianlenz
Copy link

Hi @josefaidt! It's possible documentation can be improved, but was there an intentional, breaking change from Amplify CLI 9.1.0 to the current Amplify CLI version? The behavior has changed, which is forcing us to stay pinned on an old CLI version.

The Monorepo setup works great in Amplify CLI 9.1.0. Upgrading beyond it breaks the Amplify frontend build with this error.

Here's our setup:

|- repo/
|-- amplify.yml
|-- amplify/
|-- app/ (React Native project)
|--- package.json
|-- web/ (Next.js project)
|--- package.json

The amplify.yml sets the webRoot to the web directory where the front end is built and deployed. It would be great if this can continue to be supported in the CLI as it was in 9.1.0. Are you suggesting that we need to duplicate the amplify directory in the web directory in order to have compatibility with the latest CLI versions? Is there some reason that this stopped working in a minor CLI version release?

Thanks!

@josefaidt
Copy link
Contributor

Hey @brianlenz

was there an intentional, breaking change from Amplify CLI 9.1.0 to the current Amplify CLI version?

This was an intentional change but was not meant to break existing workflows where this fix uncovered a subtle difference in the monorepo support. Previously the functionality would have pulled your amplify/ directory into repo/web/amplify/ and initialize from there rather than using the amplify/ directory at your monorepo root.

The monorepo support functionality is to enable folks to have multiple Amplify projects in a single repo, where we can connect the same repo to multiple apps for automated builds.

Are you suggesting that we need to duplicate the amplify directory in the web directory in order to have compatibility with the latest CLI versions?

Great question! The short answer is no, you need not to duplicate this directory. Instead, it may be worth exploring the following options:

  • change directories in the backend build step to your monorepo root: cd ../..; amplifyPush --simple; cd -
  • remove the appRoot in favor of a monolithic buildspec, where commands such as amplifyPush will be executed from the monorepo root rather than your app, and cd into your app or build from the root with workspace commands such as yarn workspace my-app run build

I'll be working closely with a few folks from the Amplify Hosting team to get this documentation and guide updated 🙂

@brianlenz
Copy link

@josefaidt, thanks much for the quick response! We don't do any automated backend builds or pushes (we have Enable full-stack continuous deployments (CI/CD) turned off). We have an Amplify backend configured, but we manage it purely through the Amplify CLI (with manual invocations of amplify push). We are using the Amplify Hosting to build the front end, and that's where the monorepo issue lies for us (and I suspect other people here).

Contrary to the use case you mentioned, we have a single Amplify project (so, a single backend) that we use with multiple Amplify "front ends" (one React Native, one Next.js). React Native is built manually, of course, but the Next.js uses automated builds through Amplify Hosting, which is where our Amplify CLI option is forced to 9.1.0. Our amplify.yml is pretty standard. There are a couple of trivial custom commands, but it otherwise just does a yarn run build for Next.js with appRoot: web.

It seems that your suggestions are focused on automated backend builds and pushes, which we don't do. Our problem is purely with the Amplify Hosting build process for the Next.js front end. As such, I'm not sure the options that you suggested are relevant to our use case?

Does this added context give you any other ideas as to how we might upgrade to the latest Amplify CLI?

FWIW, this:

Previously the functionality would have pulled your amplify/ directory into repo/web/amplify/ and initialize from there rather than using the amplify/ directory at your monorepo root.

sounds like exactly what we want and need. It's unfortunate that it's no longer supported on the latest versions of the Amplify CLI 😕

@khandaresuyash
Copy link

Error: Creating a nested amplify project is not supported. Project root detected: /Users/suyashkhandare
Getting the same error for my newly created flutter project

Downgrading to 9.1.0. Won't work

@josefaidt josefaidt added the hosting Issues tied to hosting category label Sep 22, 2022
@neal3000
Copy link

neal3000 commented Oct 2, 2022

I am getting this error on amplify init , try to add amplify to a new Xcode project
Error: Creating a nested amplify project is not supported. Project root detected: /Users/xxxxx
at checkForNestedProject (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/helpers/projectUtils.js:9:15)
at Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/init.js:28:50)
at Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:292:29)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:165:13)
npm -v
8.19.2
node -v
v17.2.0
amplify -v
10.0.0
pwd
/Users/xxxx/Development/Notify1

@josefaidt
Copy link
Contributor

Hey @neal3000 do you have an amplify directory at /Users/xxxxx?

@hirveakshata
Copy link

Getting this problem too when running amplify init inside a blank directory

I'm also facing the same problem.

@israx
Copy link
Member

israx commented Jan 29, 2023

I had an amplify directory created by mistake at a parent root. I deleted it and worked.

@Tstepro
Copy link

Tstepro commented Apr 30, 2023

I had an amplify directory created at /Users/xxxx. Deleting that resolved it.

@hadils
Copy link

hadils commented Oct 16, 2023

I am having this problem. I have tried all the suggestions above to no avail. I have a monorepo with my web pages in the web/ subdirectory of the repo. I cannot find another instance of amplify anywhere in my system.

@islalr
Copy link

islalr commented Dec 15, 2023

I had the same issues as above, a mono repo with the /amplify directory above the /artifacts/web appRoot. Managed to solve it by changing the build.yml file in Amplify Console. Didn't want to change my structure or downgrade, here's the script.


version: 1 
applications:
  - appRoot: artifacts/web
    env:
      variables:
        key: value
    frontend:
      phases:
        # IMPORTANT - Please verify your build commands
        build:
          commands: []
      artifacts:
        # IMPORTANT - Please verify your build output directory
        baseDirectory: /
        files:
          - '**/*'
      cache:
        paths: []
    backend:
      phases:
        preBuild:
          commands:
            - cd ..; amplifyPush --simple; cd -

@OperationalFallacy
Copy link

Didn't they retire amplifyPush script?

https://github.com/aws-amplify/amplify-hosting/blob/main/scripts/amplifyPush.sh

@thegrandpoobah
Copy link

thegrandpoobah commented Jan 22, 2024

This might not be useful, but I just started experiencing this issue as well.

Amplify CLI version on my workstation: 12.10.0
Amplify CLI version on the CI: 12.10.1 (i assume)

project structure:

/repo
  /amplify
  amplify.yml
  allll the other files for a vue.js frontend here (/src, /public, package.json, etc etc etc)

Up until todays push, everything was working fine, but I pushed a bunch of changes to backend (updated functions, changed schema etc) AND the amplify.yml file and receive that error now.

I tried a couple of the solutions here to no avail.

The amplify.yml file:

 version: 1
backend:
  phases:
    # IMPORTANT - Please verify your build commands
    preBuild:
      commands:
        - npm install -g @aws-amplify/cli
    build:
      commands:
        - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3
        - ln -fs /usr/local/bin/python3.8 /usr/bin/python3
        - pip3 install --user pipenv
        #- pip3 install --upgrade setuptools
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands: 
        - echo "VUE_APP_RECAPTCHA=$RECAPTCHA" >> .env
        - echo "VUE_APP_GOOGLE_SITE_KEY=$GOOGLE_SITE_KEY" >> .env
        - npm run build
  artifacts:
    baseDirectory: dist/spa
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
test:
  phases:
    preTest:
      commands:
        - if [ "${AWS_BRANCH}" = "test" ]; then echo "test branch"; fi
    test:
      commands:
        #-if [ "${AWS_BRANCH}" = "test" ]; then curl -X POST https://app.testsigma.com/api/v1/execution_results -H '"Content-type:application/json"' -H "Authorization:$TESTSIGMA_API_KEY"  -d '{"executionId":"651"}'; fi
    postTest:
      commands:
        - if [ "${AWS_BRANCH}" = "test" ]; then echo "test completed"; fi
  artifacts:
    baseDirectory: dist/spa
    files:
      - '**/*'

If I remove the amplify.yml file from the repository and just use the one in the web ui, it seems to work okay, which I guess is workable..

@DomGarza
Copy link

Hey y'all I just wanted to offer another solution. I had this issue because I accidentally committed my amplify folder to github which causes the nested issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Add or update documentation hosting Issues tied to hosting category platform Issues tied to the general CLI platform
Projects
None yet
Development

No branches or pull requests