aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.83k stars 823 forks source link

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

Open chris-mds opened 2 years ago

chris-mds commented 2 years ago

Before opening, please confirm:

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)

```graphql # Put schemas below this line ```

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

josefaidt commented 2 years ago

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

chris-mds commented 2 years ago

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 commented 2 years ago

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.

bkmulusew commented 2 years ago

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

lazpavel commented 2 years ago

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 commented 2 years ago

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

jeffearthx commented 2 years ago

@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 commented 2 years ago

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?

jeffearthx commented 2 years ago

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 commented 2 years ago

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 amplify-cli@amazon.com 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 commented 2 years ago

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 commented 2 years ago

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

thanks

brianlenz commented 2 years ago

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 commented 2 years ago

Same issue for me. Downgrading to 9.1.0 solved it.

gcmerz commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Hey folks :wave: 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 commented 2 years ago

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 commented 2 years ago

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:

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

brianlenz commented 2 years ago

@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 commented 2 years ago

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

neal3000 commented 2 years ago

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 commented 2 years ago

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

hirveakshata commented 1 year ago

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

I'm also facing the same problem.

israx commented 1 year ago

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

Tstepro commented 1 year ago

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

hadils commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago

Didn't they retire amplifyPush script?

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

thegrandpoobah commented 10 months ago

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..