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:
aws-exports
file:
const awsmobile = {
"aws_project_region": "us-east-1",
"aws_cognito_identity_pool_id": "us-east-1:xxx-xxxx-xxxx-xxxx-xxxxxxxx",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "us-east-1_xxx",
"aws_user_pools_web_client_id": "xxxx",
"oauth": {}
};
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]: > [email protected] 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]: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
[96m>[94m https://opencollective.com/core-js [0m
[96m>[94m https://www.patreon.com/zloirock [0m
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
2020-06-02T23:55:06.601Z [INFO]: > [email protected] 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]: > [email protected] 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]: > [email protected] postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
2020-06-02T23:55:06.842Z [INFO]: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
[96m>[94m https://opencollective.com/core-js [0m
[96m>[94m https://www.patreon.com/zloirock [0m
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
2020-06-02T23:55:06.957Z [INFO]: > [email protected] 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]: > [email protected] 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]: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
[96m>[94m https://opencollective.com/core-js [0m
[96m>[94m https://www.patreon.com/zloirock [0m
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
2020-06-02T23:55:07.187Z [INFO]: > [email protected] 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]: > [email protected] 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]: > [email protected] postinstall /codebuild/output/src218102989/src/XXXXXXXX/node_modules/fast-xml-parser
> node tasks/postinstall.js || exit 0
2020-06-02T23:55:07.909Z [INFO]: [96m[1mLove fast-xml-parser? Check [32mhttps://amitkumargupta.work [96m[1mfor more projects and contribution.[0m
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]: > [email protected] 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'.
@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
);
If you still have an issue, ping here and I will reopen the issue.
@ashika01 Thank you - yes, it was gitignored.
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?
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.
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.
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.
Most helpful comment
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?