skip to Main Content

I have an amplify project in React and I set up the front end pages already using React-Router etc.. and deployed on amplify and it was working great.

Now I want to add a backend so I ran:

npm create amplify@latest

it creates an amplify folder and creates amplify_outputs.json locally but when I try and deploy the latest commit I am getting a build error:

2024-10-03T15:49:01.443Z [INFO]: src/App.tsx(10,21): error TS2307: Cannot find module '../amplify_outputs.json' or its corresponding type declarations.

I see that amplify_outputs.json was added to the git ignore automatically but its not getting generated on the build so was wondering if I should remove it from the git ignore but it has a user_pool_client_id in it so Im pretty sure its supposed be generated on the build.

2

Answers


  1. Chosen as BEST ANSWER

    Hi I did have to add a amplify.yaml but through different testing this is what I needed:

    version: 1
    backend:
      phases:
        build:
          commands:
            - npm ci --cache .npm --prefer-offline
            - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
    frontend:
      phases:
        build:
          commands:
            - npm run build
      artifacts:
        baseDirectory: dist
        files:
          - '**/*'
      cache:
        paths:
          - .npm/**/*
          - node_modules/**/*
    

  2. amplify_outputs.json should be in in .gitignore since it can change as the environment or resources change.

    First ensure that the backend is correctly deployed by running amplify push then amplify pull --appId APP_ID to regenerate the amplify_outputs.json file locally.

    If the above doesn’t work, try adding this to amplify.yml file:

    preBuild:
      commands:
        - npm ci
        - amplify pull --appId APP_ID --envName ENV_NAME
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search