aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.13k forks source link

Build Fails Only on Amplify with Error "Cannot find file '../aws-exports' in './src/components'." #5979

Closed bholbrook73 closed 4 years ago

bholbrook73 commented 4 years ago

Describe the bug

The build in Amplify fails with error message "Cannot find file '../aws-exports' in './src/components'."

This works locally with npm run build and I'm able to access the API using the aws_exports locally. amplify push works as expected without issue.

When pushing to the repo and triggering a build, the build fails on all branches.

To Reproduce Push a change to any branch in Amplify App arn:aws:amplify:us-east-1:958024423534:apps/d121a0czlswxc1

Expected behavior Expect app to build without error

Code Snippet Folder structure:

src/ components/ Quote.tsx awx-exports.js

Quote.tsx imports:

import React, {useState} from "react";
import Amplify, { API } from 'aws-amplify';
import aws_exports from '../aws-exports.js';
Amplify.configure(aws_exports);

What is Configured?

aws-exports:

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_cognito_identity_pool_id": "us-east-1:c8f456df-f75f-4468-9568-5588a5349db1",
    "aws_cognito_region": "us-east-1",
    "oauth": {},
    "aws_cloud_logic_custom": [
        {
            "name": "api797228ba",
            "endpoint": "https://7eqzr4g724.execute-api.us-east-1.amazonaws.com/prod",
            "region": "us-east-1"
        }
    ]
};

export default awsmobile;

If applicable, please provide what is configured for Amplify CLI:

npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages

  System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 650.51 MB / 15.52 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
    npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
  Browsers:
    Chrome: 80.0.3987.122
    Firefox: 76.0.1
  npmPackages:
    @fortawesome/fontawesome-svg-core: ^1.2.28 => 1.2.28 
    @fortawesome/free-brands-svg-icons: ^5.13.0 => 5.13.0 
    @fortawesome/free-solid-svg-icons: ^5.13.0 => 5.13.0 
    @fortawesome/react-fontawesome: ^0.1.9 => 0.1.9 
    @testing-library/jest-dom: ^4.2.4 => 4.2.4 
    @testing-library/react: ^9.5.0 => 9.5.0 
    @testing-library/user-event: ^7.2.1 => 7.2.1 
    @types/jest: ^24.9.1 => 24.9.1 
    @types/lodash: ^4.14.150 => 4.14.150 
    @types/node: ^12.12.39 => 12.12.39 
    @types/react: ^16.9.35 => 16.9.35 
    @types/react-dom: ^16.9.8 => 16.9.8 
    @types/react-scroll: ^1.5.5 => 1.5.5 
    @types/webpack-env: ^1.15.2 => 1.15.2 
    aws-amplify: ^3.0.13 => 3.0.13 
    aws-amplify-react: ^4.1.12 => 4.1.12 
    axios: ^0.19.2 => 0.19.2 
    bootstrap: ^4.5.0 => 4.5.0 
    gh-pages: ^2.2.0 => 2.2.0 
    lodash: ^4.17.15 => 4.17.15 
    node-sass: ^4.14.1 => 4.14.1 
    react: ^16.13.1 => 16.13.1 
    react-bootstrap: ^1.0.1 => 1.0.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.1 => 3.4.1 
    react-scroll: ^1.7.16 => 1.7.16 
    typescript: ^3.7.5 => 3.7.5 
  npmGlobalPackages:
    @aws-amplify/cli: 4.21.0
    bower: 1.8.8
    create-react-app: 3.4.1
    ember-cli: 3.16.0
    firebase-tools: 7.13.1
    generator-swaggerize: 4.1.0
    grunt-cli: 1.3.2
    lerna: 3.20.2
    npm: 6.13.4
    tsoa: 2.5.13
    typescript: 3.8.3
    yo: 3.1.1

Additional context Logs of build

                                 # Starting phase: preBuild
                                 # Executing command: npm ci
2020-06-02T23:54:55.876Z [WARNING]: npm
2020-06-02T23:54:55.877Z [WARNING]: WARN prepare removing existing node_modules/ before installation
2020-06-02T23:55:06.448Z [INFO]: > core-js@2.6.11 postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/babel-runtime/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2020-06-02T23:55:06.498Z [INFO]: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
                                 The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
                                 > https://opencollective.com/core-js 
                                 > https://www.patreon.com/zloirock 
                                 Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2020-06-02T23:55:06.601Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src218102989/src/XXXXXXXX/node_modules/webpack-dev-server/node_modules/fsevents
                                 > node install.js
2020-06-02T23:55:06.650Z [INFO]: 
2020-06-02T23:55:06.650Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-06-02T23:55:06.664Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src218102989/src/XXXXXXXX/node_modules/watchpack/node_modules/fsevents
                                 > node install.js
2020-06-02T23:55:06.713Z [INFO]: 
2020-06-02T23:55:06.714Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-06-02T23:55:06.794Z [INFO]: > core-js@3.6.5 postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2020-06-02T23:55:06.842Z [INFO]: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
                                 The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
                                 > https://opencollective.com/core-js 
                                 > https://www.patreon.com/zloirock 
                                 Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2020-06-02T23:55:06.957Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src218102989/src/XXXXXXXX/node_modules/jest-haste-map/node_modules/fsevents
                                 > node install.js
2020-06-02T23:55:07.006Z [INFO]: 
2020-06-02T23:55:07.007Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2020-06-02T23:55:07.057Z [INFO]: > core-js-pure@3.6.5 postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/core-js-pure
                                 > node -e "try{require('./postinstall')}catch(e){}"
2020-06-02T23:55:07.106Z [INFO]: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
                                 The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
                                 > https://opencollective.com/core-js 
                                 > https://www.patreon.com/zloirock 
                                 Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2020-06-02T23:55:07.187Z [INFO]: > node-sass@4.14.1 install /codebuild/output/src218102989/src/XXXXXXXX/node_modules/node-sass
                                 > node scripts/install.js
2020-06-02T23:55:07.481Z [INFO]: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-57_binding.node
2020-06-02T23:55:07.585Z [INFO]: Download complete
2020-06-02T23:55:07.588Z [INFO]: Binary saved to /codebuild/output/src218102989/src/XXXXXXXX/node_modules/node-sass/vendor/linux-x64-57/binding.node
2020-06-02T23:55:07.614Z [INFO]: Caching binary to /root/.npm/node-sass/4.14.1/linux-x64-57_binding.node
2020-06-02T23:55:07.633Z [INFO]: > node-sass@4.14.1 postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/node-sass
                                 > node scripts/build.js
2020-06-02T23:55:07.754Z [INFO]: Binary found at /codebuild/output/src218102989/src/XXXXXXXX/node_modules/node-sass/vendor/linux-x64-57/binding.node
2020-06-02T23:55:07.756Z [INFO]: Testing binary
2020-06-02T23:55:07.843Z [INFO]: Binary is fine
2020-06-02T23:55:07.863Z [INFO]: > fast-xml-parser@3.17.3 postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/fast-xml-parser
                                 > node tasks/postinstall.js || exit 0
2020-06-02T23:55:07.909Z [INFO]: Love fast-xml-parser? Check https://amitkumargupta.work for more projects and contribution.
2020-06-02T23:55:07.937Z [WARNING]: added 1910 packages in 12.082s
2020-06-02T23:55:07.947Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: npm run build
2020-06-02T23:55:08.097Z [INFO]: > hunters@0.2.0 build /codebuild/output/src218102989/src/XXXXXXXX
                                 > react-scripts build
2020-06-02T23:55:09.241Z [INFO]: Creating an optimized production build...
2020-06-02T23:55:14.445Z [INFO]: Failed to compile.
2020-06-02T23:55:14.446Z [INFO]: ./src/components/Quote.tsx
                                 Cannot find file '../aws-exports' in './src/components'.
ashika01 commented 4 years ago

@bholbrook73 do your repo hasaws-exports in that location? It is not git ignored? This is definitely not an issue with amplify. it looks like your aws exports isn't being referenced right. In any case, you can always configure the info manually.

Like copy the aws-exports object value and configure it using

Amplify.configure(
//paste the aws-exports value here
);
ashika01 commented 4 years ago

If you still have an issue, ping here and I will reopen the issue.

bholbrook73 commented 4 years ago

@ashika01 Thank you - yes, it was gitignored.

SleeplessFox commented 4 years ago

Is it a good solution to add the aws-exports file to github? Is there not data which should be secured and not pushed to the repo? Maybe is it possible to configure this properties directly into the amplify console?

duncangroenewald commented 4 years ago

You shouldn't be adding the aws-exports.js file to the repo because if you chose to deploy to a different environment then all the settings will be wrong for that environment. As I understand it AWS Amplify will automatically create this file for you when it runs the deploy process, depending on the environment you have chosen.

Also you appear to be referencing the path '/src/components/aws-exports' when it will be created in the 'src/' folder by Amplify CI/CD.

Nevertheless this file does not appear to be created at the moment as I can getting the same error.

pagameba commented 4 years ago

I'm having the same issue trying to deploy my project using amplify console, the aws-exports file is git-ignored because it contains the values for each of the developers using it locally. What is the correct way to set up an amplify project in the console? If I deploy it from the command line, I can't set it up for CD in the console.

dferguson992 commented 3 years ago

Has there been any updates to this? Encountering the same issue. Only way around I can see is having branch based aws-export files. Unless you are developing have specific deployment branches that can never be reconciled from master, there doesn't seem to be a way to do this currently.

SaiCharan21 commented 3 years ago

I am also having the same problem with the was-exports file not being found but I checked all of it it is all in the correct directory. Here is my log error: Cannot find file './aws-exports' in './src'. 2021-04-01T03:02:40.021Z [WARNING]: npm 2021-04-01T03:02:40.021Z [WARNING]: ERR! code ELIFECYCLE npm ERR! errno 1 2021-04-01T03:02:40.023Z [WARNING]: npm 2021-04-01T03:02:40.023Z [WARNING]: ERR! hoa-plus-amplify@0.1.0 build:react-scripts build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the hoa-plus-amplify@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2021-04-01T03:02:40.061Z [WARNING]: 2021-04-01T03:02:40.061Z [WARNING]: npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-04-01T03_02_40_023Z-debug.log

chrisac309 commented 3 years ago

Hey all, I think I found the problem.

Take a look at your AWS Amplify Console, and go to App Settings > Build Settings. Ensure that the following is present in the ``` build.yml file:

backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple

For whatever reason, this was missing from my build.yml file. Adding it should get you at least one step further! This configuration change is referenced (read: Hidden) here: https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-three/

SaiCharan21 commented 3 years ago

I am still having the same problem.. Here is my build file: version: 1 frontend: phases: preBuild: commands:

chrisac309 commented 3 years ago

@SaiCharan21 Try to flip the order of the two. You need to build the backend before building the frontend. Check the example shown in the URL I posted earlier as well, they list their backend before the frontend in the build.yml file. Here's mine as well for reference. PLEASE NOTE - I am using expo CLI, do not copy mine verbatim. Just use it for reference on the structure of the file

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm install
        - nvm use 10
        - npm install --silent --global expo-cli
        - |-
          if [ -f yarn.lock ]; then
           yarn
          elif [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
           npm ci
          else
           npm install
          fi
    build:
      commands:
        - 'expo build:web'
  artifacts:
    baseDirectory: web-build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - $(npm root --global)/**/*
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.