aws-amplify / amplify-cli

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

error TS2307: Cannot find module './amplifyconfiguration.json' or its corresponding type declarations in build stage #13864

Closed hbapps20 closed 2 months ago

hbapps20 commented 2 months ago

How did you install the Amplify CLI?

npm

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

20.15.1

Amplify CLI Version

12.12.4

What operating system are you using?

Windows

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

No manual changes made

Describe the bug

Cannot find module ."/amplifyconfiguration.json" I'm trying to build and deploy with amplify my angular + ionic application. Buildin locally it seems to be no issue, but when amplify runs CICD, it fails.

Logs from amplify:

2024-07-19T22:09:30.165Z [INFO]: # Cloning repository: git@github.com:hbapps20/001-flai.git
2024-07-19T22:09:31.436Z [INFO]: 
2024-07-19T22:09:31.437Z [INFO]: Cloning into '001-flai'...
2024-07-19T22:09:31.437Z [INFO]: # Switching to commit: 6edee5a63d58628dd086e42f0391384beb5d4006
2024-07-19T22:09:31.459Z [INFO]: Note: switching to '6edee5a63d58628dd086e42f0391384beb5d4006'.
                                 You are in 'detached HEAD' state. You can look around, make experimental
                                 changes and commit them, and you can discard any commits you make in this
                                 state without impacting any branches by switching back to a branch.
                                 If you want to create a new branch to retain commits you create, you may
                                 do so (now or later) by using -c with the switch command. Example:
                                 git switch -c <new-branch-name>
                                 Or undo this operation with:
                                 git switch -
                                 Turn off this advice by setting config variable advice.detachedHead to false
                                 HEAD is now at 6edee5a changes in scss
2024-07-19T22:09:31.532Z [INFO]: Successfully cleaned up Git credentials
2024-07-19T22:09:31.533Z [INFO]: # Checking for Git submodules at: /codebuild/output/src1366782704/src/xxx/.gitmodules
2024-07-19T22:09:31.541Z [INFO]: # Retrieving environment cache...
2024-07-19T22:09:31.583Z [WARNING]: ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})}
2024-07-19T22:09:31.583Z [INFO]: ---- Setting Up SSM Secrets ----
2024-07-19T22:09:31.583Z [INFO]: SSM params {"Path":"/amplify/xxxx/master/","WithDecryption":true}
2024-07-19T22:09:31.709Z [INFO]: # Determining if there are buildable backend changes in the amplify directory of the repository...
2024-07-19T22:09:31.738Z [INFO]: # No differences detected.
2024-07-19T22:09:34.536Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 12.8.2 to 12.12.4...
2024-07-19T22:10:05.199Z [INFO]: # Installed '@aws-amplify/cli@12.12.4'
2024-07-19T22:10:05.289Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 12.12.4
2024-07-19T22:10:05.300Z [INFO]: # Retrieving cache...
2024-07-19T22:10:05.342Z [INFO]: # Retrieved cache
2024-07-19T22:10:07.804Z [INFO]: ## Processing Environment Variables
                                 # Set Environment Variable: USER_BRANCH
2024-07-19T22:10:07.806Z [INFO]: ## Starting Backend Build
                                 ## Checking for associated backend environment...
2024-07-19T22:10:07.807Z [INFO]: ## No backend environment association found, continuing...
                                 ## Completed Backend Build
2024-07-19T22:10:07.810Z [INFO]: ## Starting Frontend Build
                                 # Starting phase: build
2024-07-19T22:10:07.810Z [INFO]: # Executing command: echo Build started on `date`
2024-07-19T22:10:07.812Z [INFO]: Build started on Fri Jul 19 22:10:07 UTC 2024
2024-07-19T22:10:07.812Z [INFO]: # Executing command: echo Installing Ionic...
                                 Installing Ionic...
                                 # Executing command: npm install -g @ionic/cli
2024-07-19T22:10:13.693Z [WARNING]: npm
2024-07-19T22:10:13.701Z [WARNING]: WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
2024-07-19T22:10:13.792Z [WARNING]: npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
2024-07-19T22:10:13.825Z [WARNING]: npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
2024-07-19T22:10:14.132Z [WARNING]: npm WARN deprecated superagent@8.1.2: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net
2024-07-19T22:10:15.005Z [INFO]: added 204 packages in 7s
2024-07-19T22:10:15.005Z [INFO]: 33 packages are looking for funding
                                 run `npm fund` for details
2024-07-19T22:10:15.016Z [INFO]: # Executing command: echo Installing Ionic and Angular
                                 Installing Ionic and Angular
2024-07-19T22:10:15.016Z [INFO]: # Executing command: npm install @ionic/angular@8.1.2 --save
2024-07-19T22:10:27.599Z [WARNING]: npm
2024-07-19T22:10:27.604Z [WARNING]: WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
2024-07-19T22:10:29.169Z [WARNING]: npm WARN deprecated @types/aws-sdk@2.7.0: This is a stub types definition for aws-sdk (https://github.com/aws/aws-sdk-js). aws-sdk provides its own type definitions, so you don't need @types/aws-sdk installed!
2024-07-19T22:10:53.640Z [INFO]: added 1617 packages, and audited 1654 packages in 38s
2024-07-19T22:10:53.645Z [INFO]: 207 packages are looking for funding
                                 run `npm fund` for details
2024-07-19T22:10:53.654Z [INFO]: 2 moderate severity vulnerabilities
                                 To address all issues, run:
                                 npm audit fix --force
                                 Run `npm audit` for details.
2024-07-19T22:10:53.688Z [INFO]: # Executing command: echo User Branch $USER_BRANCH
                                 User Branch master
2024-07-19T22:10:53.688Z [INFO]: # Executing command: if [ $USER_BRANCH = "master" ]; then ionic build; fi
2024-07-19T22:10:54.128Z [INFO]: > ng run app:build
2024-07-19T22:10:55.515Z [WARNING]: One or more browsers which are configured in the project's Browserslist configuration will be ignored as ES5 output is not supported by the Angular CLI.
                                    Ignored browsers: chrome 60
2024-07-19T22:10:55.524Z [WARNING]: - Generating browser application bundles (phase: setup)...
2024-07-19T22:11:42.967Z [WARNING]: ✔ Browser application bundle generation complete.
2024-07-19T22:11:44.099Z [WARNING]: ✔ Browser application bundle generation complete.
2024-07-19T22:11:44.102Z [WARNING]: Warning: /codebuild/output/src1366782704/src/001-flai/node_modules/@aws-amplify/auth/dist/esm/providers/cognito/apis/signOut.mjs depends on '@aws-crypto/sha256-js'. CommonJS or AMD dependencies can cause optimization bailouts.
                                    For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
                                    Warning: /codebuild/output/src1366782704/src/001-flai/src/app/orders/orders/edit-order/edit-order.page.scss exceeded maximum budget. Budget 2.00 kB was not met by 1.24 kB with a total of 3.24 kB.
                                    Warning: /codebuild/output/src1366782704/src/001-flai/src/app/orders/orders/new-order/new-order.page.scss exceeded maximum budget. Budget 2.00 kB was not met by 1.57 kB with a total of 3.57 kB.
2024-07-19T22:11:44.102Z [WARNING]: ./src/main.ts:10:0-56 - Error: Module not found: Error: Can't resolve './amplifyconfiguration.json' in '/codebuild/output/src1366782704/src/001-flai/src'
                                    Error: src/main.ts:13:21 - error TS2307: Cannot find module '../amplify_outputs.json' or its corresponding type declarations.
                                    13 import outputs from "../amplify_outputs.json";
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~
                                    Error: src/main.ts:15:27 - error TS2307: Cannot find module './amplifyconfiguration.json' or its corresponding type declarations.
                                    15 import amplifyconfig from './amplifyconfiguration.json';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-07-19T22:11:44.225Z [WARNING]: [ERROR] An error occurred while running subprocess ng.

                                    ng run app:build exited with exit code 1.

                                    Re-running this command with the --verbose flag may provide more information.
2024-07-19T22:11:44.238Z [ERROR]: !!! Build failed
2024-07-19T22:11:44.239Z [ERROR]: !!! Error: Command failed with exit code 1
2024-07-19T22:11:44.239Z [INFO]: # Starting environment caching...
2024-07-19T22:11:44.239Z [INFO]: # Environment caching completed

this is my amplify.yml file:

version: 0.2

env:
  variables:
    USER_BRANCH: $USER_BRANCH
    #ENV: $ENV

# backend:
#   phases:
#     build:
#       commands:
#         - echo Installing backend...
#         - amplifyPush --simple

frontend:
  phases:      
    build:
      commands:
        - echo Build started on `date`
        # - echo Install source NPM dependencies....
        # - npm install 
        - echo Installing Ionic...
        - npm install -g @ionic/cli
        - echo Installing Ionic and Angular
        - npm install @ionic/angular@8.1.2 --save  
        - echo User Branch $USER_BRANCH
        - if [ $USER_BRANCH = "master" ]; then ionic build; fi
        #- if [ $USER_BRANCH = "test" ]; then ionic build --configuration=test; fi      
    post_build:
      commands:
        - echo Build completed on `date` 

  artifacts:
    #baseDirectory: public
    baseDirectory: /www
    files:
      - '**/*'

  cache:
    paths:
      - node_modules/**/*

And this is amplify role: amplifyconsole-backend-role-aw001-flai

image

Expected behavior

I expect that amplify build and deploy in the cloud my application

Reproduction steps

  1. Create angular project
  2. Create amplify project with cdk
  3. Init project with amplify init --appId xxx in angular project
  4. make some changes to master branch
  5. commit and push changes

Project Identifier

No response

Log output

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

Additional information

package.json file

{
  "name": "xxxx",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^17.3.7",
    "@angular/core": "^17.3.7",
    "@angular/forms": "^17.3.9",
    "@angular/google-maps": "^17.3.9",
    "@angular/platform-browser": "^17.3.7",
    "@angular/platform-browser-dynamic": "^17.3.9",
    "@angular/router": "^17.3.9",
    "@aws-sdk/client-ses": "^3.577.0",
    "@capacitor/app": "4.1.1",
    "@capacitor/core": "4.6.2",
    "@capacitor/haptics": "4.1.0",
    "@capacitor/keyboard": "4.1.1",
    "@capacitor/status-bar": "4.1.1",
    "@ionic/angular": "^8.1.2",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "aws-amplify": "^6.3.2",
    "crypto-secure-random-digit": "^1.0.10",
    "ionicons": "^6.1.3",
    "libphonenumber-js": "^1.11.1",
    "node": "^22.2.0",
    "rxjs": "~7.5.0",
    "swiper": "^11.1.3",
    "underscore": "^1.13.6",
    "zone.js": "^0.14.6"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^17.3.7",
    "@angular-eslint/builder": "^14.4.0",
    "@angular-eslint/eslint-plugin": "^14.4.0",
    "@angular-eslint/eslint-plugin-template": "^14.4.0",
    "@angular-eslint/template-parser": "^14.4.0",
    "@angular/cli": "^17.3.7",
    "@angular/compiler": "^17.3.7",
    "@angular/compiler-cli": "^17.3.9",
    "@angular/language-service": "^17.3.9",
    "@capacitor/cli": "4.6.2",
    "@ionic/angular-toolkit": "^11.0.1",
    "@types/aws-sdk": "^2.7.0",
    "@types/google.maps": "^3.55.9",
    "@types/jasmine": "~4.0.0",
    "@types/jest": "^29.5.12",
    "@types/node": "^12.20.55",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "aws-cdk": "^2.142.1",
    "aws-cdk-lib": "^2.142.1",
    "constructs": "^10.3.0",
    "esbuild": "^0.21.3",
    "eslint": "^7.32.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~4.3.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "ts-node": "~8.3.0",
    "tslib": "^2.5.0",
    "tsx": "^4.10.5",
    "typescript": "^5.4.5"
  },
  "description": "An Ionic project"
}

Before submitting, please confirm:

hbapps20 commented 2 months ago

I find the solution, what was wrong is that I wasan't executing the backend phase in the CICD amplify.yml file, which is the one I think that generates the amplifyconfiguration.json file, soy I add the following code to my ammplify.yaml file:

backend:
  phases:
    build:
      commands:
        - echo Installing backend...
        - amplifyPush --simple
ykethan commented 2 months ago

Hey @hbapps20, glad to hear you were able to mitigate the issue. Amplify CLI generates the amplify-configuration.json on a push or pull. Closing the issue.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.