Amplify-js: Build Fails During Amplify Deploy Because "cannot find file './components/...'"

Created on 4 Dec 2019  ·  3Comments  ·  Source: aws-amplify/amplify-js

Describe the bug
A clear and concise description of what the bug is.

I am trying to deploy my Amplify app via the Amplify console. The build fails every time because it fails to compile. The reason is stated as:

Failed to compile.
./src/App.js
Cannot find file './components/DisplayWrappers/NavBar/NavBar' in './src'

The file definitely exists. I have retried deploying after removing everything from the App component and replacing it with a simple <p>TEST</p> element, which successfully deploys.

I have tried changing the components folder to Components and updating all import statements. This fails. I have tried removing the NavBar import and the NavBar component from App.js, but it just fails on another './components/...' import deeper in the app. I have also tried deploying other branches, and all of these fail with the same error as above above.

NOTE: Wild guess, but could it be to do with the fact that Amplify deploys to a Linux machine, which has a case-sensitive file system? I have checked all the capitalisations of my import statements and my folder/file structure and they do match... See here for more info about what I am referring to:
https://gist.github.com/koistya/d7a507438c741ee6adb5#gistcomment-1701432

Here are the build logs from Amplify console:

2019-12-04T18:37:49.799Z [INFO]: Git SSH Key acquired
2019-12-04T18:37:49.885Z [INFO]: # Cloning repository: [email protected]:ph0ph0/voz-de-pr.git
2019-12-04T18:37:50.041Z [INFO]: Agent pid 71
2019-12-04T18:37:50.046Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2019-12-04T18:37:50.278Z [INFO]: Cloning into 'voz-de-pr'...
2019-12-04T18:37:50.638Z [INFO]: Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
2019-12-04T18:37:51.110Z [INFO]: # Checking for Git submodules at: /codebuild/output/src902333202/src/voz-de-pr/.gitmodules
2019-12-04T18:37:51.133Z [INFO]: # Retrieving cache...
2019-12-04T18:37:51.195Z [INFO]: # Extracting cache...
2019-12-04T18:37:51.504Z [INFO]: # Extraction completed
2019-12-04T18:37:51.505Z [INFO]: # Retrieving environment cache...
2019-12-04T18:37:51.622Z [INFO]: # Retrieved environment cache
2019-12-04T18:37:51.623Z [INFO]: # Ensuring NPM package '@aws-amplify/cli' is version: 'latest'
2019-12-04T18:38:02.252Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 1.12.0 to 4.5.0...
2019-12-04T18:38:59.609Z [INFO]: # Done patching NPM package '@aws-amplify/cli'
2019-12-04T18:39:08.398Z [INFO]: ## Starting Frontend Build
# Starting phase: preBuild
# Executing command: yarn install
2019-12-04T18:39:09.035Z [INFO]: yarn install v1.16.0
2019-12-04T18:39:09.130Z [WARNING]: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
2019-12-04T18:39:09.132Z [INFO]: [1/4] Resolving packages...
2019-12-04T18:39:11.263Z [INFO]: [2/4] Fetching packages...
2019-12-04T18:39:26.908Z [INFO]: info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
2019-12-04T18:39:26.911Z [INFO]: info [email protected]: The platform "linux" is incompatible with this module.
2019-12-04T18:39:26.913Z [INFO]: info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
2019-12-04T18:39:26.924Z [INFO]: [3/4] Linking dependencies...
2019-12-04T18:39:26.926Z [WARNING]: warning "@storybook/react > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "react-scripts > @typescript-eslint/eslint-plugin > [email protected]" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
2019-12-04T18:39:26.933Z [WARNING]: warning "@storybook/addon-storyshots > [email protected]" has unmet peer dependency "jest@*".
warning " > @storybook/[email protected]" has unmet peer dependency "@babel/core@^7.0.1".
warning " > @storybook/[email protected]" has unmet peer dependency "babel-loader@^7.0.0 || ^8.0.0".
warning "@storybook/react > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@storybook/react > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@storybook/react > @storybook/[email protected]" has unmet peer dependency "babel-loader@^7.0.0 || ^8.0.0".
warning "@storybook/react > @storybook/core > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
2019-12-04T18:39:26.936Z [WARNING]: warning " > [email protected]" has unmet peer dependency "babel-plugin-macros@^2.4.2".
warning " > [email protected]" has unmet peer dependency "@babel/core@^7.1.2".
2019-12-04T18:39:26.938Z [WARNING]: warning " > [email protected]" has unmet peer dependency "react-router@^4.0.0||^5.0.0".
2019-12-04T18:39:37.738Z [INFO]: [4/4] Building fresh packages...
2019-12-04T18:39:38.974Z [INFO]: success Saved lockfile.
2019-12-04T18:39:38.978Z [INFO]: Done in 29.95s.
2019-12-04T18:39:38.997Z [INFO]: # Completed phase: preBuild
# Starting phase: build
2019-12-04T18:39:38.998Z [INFO]: # Executing command: yarn run build
2019-12-04T18:39:39.159Z [INFO]: yarn run v1.16.0
2019-12-04T18:39:39.187Z [INFO]: $ react-scripts build
2019-12-04T18:39:42.512Z [INFO]: Creating an optimized production build...
2019-12-04T18:39:44.661Z [INFO]: Failed to compile.
2019-12-04T18:39:44.663Z [INFO]: ./src/App.js
Cannot find file './components/DisplayWrappers/NavBar/NavBar' in './src'.
2019-12-04T18:39:44.683Z [WARNING]: error Command failed with exit code 1.
2019-12-04T18:39:44.684Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2019-12-04T18:39:44.689Z [ERROR]: !!! Build failed
2019-12-04T18:39:44.788Z [ERROR]: !!! Non-Zero Exit Code detected
2019-12-04T18:39:44.788Z [INFO]: # Starting environment caching...
2019-12-04T18:39:44.789Z [INFO]: # Environment caching completed
Terminating logging...

Can't reproduce question

Most helpful comment

I've had this same error recently!

NOTE: Wild guess, but could it be to do with the fact that Amplify deploys to a Linux machine, which has a case-sensitive file system? I have checked all the capitalisations of my import statements and my folder/file structure and they do match... See here for more info about what I am referring to:

This is likely the case: macOS + git is notorious for this.

For example, if you were to rename ./components/DisplayWrappers/NavBar/NavBar to ./components/displaywrappers/navbar/navbar, git won't see the difference.

Here's a local create-react-app project I have. Notice how I explicitly rename src/App.js to lowercase, and how git doesn't see the difference:

❯ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean


❯ mv src/App.js 'src/app.js'

❯ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

❯ ls -al src/
total 56
drwxr-xr-x  10 ecclemm  ANT\Domain Users   320 Dec  4 16:17 .
drwxr-xr-x  17 ecclemm  ANT\Domain Users   544 Dec  2 15:55 ..
-rw-r--r--   1 ecclemm  ANT\Domain Users   248 Oct 15 16:11 App.test.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  1498 Dec  4 16:12 app.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  1722 Oct  9 15:39 aws-exports.js
drwxr-xr-x  13 ecclemm  ANT\Domain Users   416 Nov 14 10:46 components
drwxr-xr-x   6 ecclemm  ANT\Domain Users   192 Oct 15 16:11 graphql
-rw-r--r--   1 ecclemm  ANT\Domain Users   430 Oct 15 16:11 index.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  4951 Oct 15 16:11 serviceWorker.js
-rw-r--r--   1 ecclemm  ANT\Domain Users   753 Nov 12 11:09 useAuth.js

There's an article on fixing this:

https://www.hanselman.com/blog/GitIsCasesensitiveAndYourFilesystemMayNotBeWeirdFolderMergingOnWindows.aspx

What I would try, in your situation, is:

  1. Renaming ./components/DisplayWrappers/NavBar/NavBar to something else, like ./components/DisplayWrappers_2/NavBar/NavBar.
  2. Commit it.
  3. Rename it _back_ to ./components/DisplayWrappers/NavBar/NavBar.
  4. Commit that.
  5. Repeat for any other errors that pop up.

Usually what happens is that you create it once with certain casing, commit it, and change the casing later, but that 2nd change is never picked up by version control. (But is picked up by linux!)

Another option is to blow away your local repo & re-clone it, which will show you what Amplify Console is seeing.

Give this a shot & let me know! If your project is open-source, I can take a look at it there, too.

Lastly, if there _is_ a bug with Amplify Console that we can reproduce, we'll move this ticket to that repo so it can be better addressed. 🤞

All 3 comments

I've had this same error recently!

NOTE: Wild guess, but could it be to do with the fact that Amplify deploys to a Linux machine, which has a case-sensitive file system? I have checked all the capitalisations of my import statements and my folder/file structure and they do match... See here for more info about what I am referring to:

This is likely the case: macOS + git is notorious for this.

For example, if you were to rename ./components/DisplayWrappers/NavBar/NavBar to ./components/displaywrappers/navbar/navbar, git won't see the difference.

Here's a local create-react-app project I have. Notice how I explicitly rename src/App.js to lowercase, and how git doesn't see the difference:

❯ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean


❯ mv src/App.js 'src/app.js'

❯ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

❯ ls -al src/
total 56
drwxr-xr-x  10 ecclemm  ANT\Domain Users   320 Dec  4 16:17 .
drwxr-xr-x  17 ecclemm  ANT\Domain Users   544 Dec  2 15:55 ..
-rw-r--r--   1 ecclemm  ANT\Domain Users   248 Oct 15 16:11 App.test.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  1498 Dec  4 16:12 app.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  1722 Oct  9 15:39 aws-exports.js
drwxr-xr-x  13 ecclemm  ANT\Domain Users   416 Nov 14 10:46 components
drwxr-xr-x   6 ecclemm  ANT\Domain Users   192 Oct 15 16:11 graphql
-rw-r--r--   1 ecclemm  ANT\Domain Users   430 Oct 15 16:11 index.js
-rw-r--r--   1 ecclemm  ANT\Domain Users  4951 Oct 15 16:11 serviceWorker.js
-rw-r--r--   1 ecclemm  ANT\Domain Users   753 Nov 12 11:09 useAuth.js

There's an article on fixing this:

https://www.hanselman.com/blog/GitIsCasesensitiveAndYourFilesystemMayNotBeWeirdFolderMergingOnWindows.aspx

What I would try, in your situation, is:

  1. Renaming ./components/DisplayWrappers/NavBar/NavBar to something else, like ./components/DisplayWrappers_2/NavBar/NavBar.
  2. Commit it.
  3. Rename it _back_ to ./components/DisplayWrappers/NavBar/NavBar.
  4. Commit that.
  5. Repeat for any other errors that pop up.

Usually what happens is that you create it once with certain casing, commit it, and change the casing later, but that 2nd change is never picked up by version control. (But is picked up by linux!)

Another option is to blow away your local repo & re-clone it, which will show you what Amplify Console is seeing.

Give this a shot & let me know! If your project is open-source, I can take a look at it there, too.

Lastly, if there _is_ a bug with Amplify Console that we can reproduce, we'll move this ticket to that repo so it can be better addressed. 🤞

Spot on, this was the issue! Thanks very much for your detailed response and for helping out!

Note to self: Update your .gitconfig 💯

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leantide picture leantide  ·  3Comments

shinnapatthesix picture shinnapatthesix  ·  3Comments

epicfaace picture epicfaace  ·  3Comments

callmekatootie picture callmekatootie  ·  3Comments

benevolentprof picture benevolentprof  ·  3Comments