aws-amplify / aws-amplify/amplify-cli

getPackageManager should fail if rootPath is provided but does not exist

Open
#10,723 4 comments 0 reactions 0 assignees View on GitHub
bug extensibility p2 platform
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### Before opening, please confirm:

- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/dev/CONTRIBUTING.md#bug-reports).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### How did you install the Amplify CLI?

npm

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

_No response_

### Amplify CLI Version

9.1.0

### What operating system are you using?

macOS 12.4

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

no changes, added a CDK based custom resource

### Amplify Categories

custom

### Amplify Commands

push

### Describe the bug

I ended up in a situation where I had a custom resource named `lambdaTriggerIotEventsCollector`(note the lower case starting character) in my backend-config.json. The directory itself however was `amplfy/backend/custom/LambdaTriggerIotEventsCollector `(note the upper case starting character of the resource name).

As per default macOS uses a case insensitive file system everything work as expected on my local machine. However when building on amplify hosting (which is Linux based and case sensitive) I received the error:

> 2022-07-04T11:53:10.839Z [INFO]: ## Starting Backend Build
> # Starting phase: build
> 2022-07-04T11:53:12.785Z [INFO]: Amplify AppID found: . Amplify App name is: 
> 2022-07-04T11:53:12.828Z [INFO]: Backend environment dev found in Amplify Console app: 
> 2022-07-04T11:53:13.597Z [WARNING]: - Fetching updates to backend environment: dev from the cloud.
> 2022-07-04T11:53:14.436Z [INFO]: Overrides functionality is not implemented for this category
> 2022-07-04T11:53:14.437Z [INFO]: Overrides functionality is not implemented for this category
> Overrides functionality is not implemented for this category
> 2022-07-04T11:53:14.437Z [WARNING]: - Building resource storage/JpegImages
> - Building resource auth/cognito88720486
> - Building resource api/orderGraphQlAPI
> - Building resource custom/lambdaTriggerIotEventsCollector
> - Building custom resources
> 2022-07-04T11:53:14.464Z [INFO]: 🛑 There was an error building the custom resources
> 2022-07-04T11:53:14.465Z [INFO]: 🛑 Error: No package manager found. Please install npm or yarn to compile overrides for this project.
> at buildResource (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:78:15)
> at runMicrotasks ()
> at processTicksAndRejections (internal/process/task_queues.js:95:5)
> at async buildCustomResources (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:43:13)
> at async transformCategoryStack (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/index.js:54:5)
> at async transformResourceWithOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/override-manager/transform-resource.js:80:9)
> at async Object.buildOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/utility-functions.js:106:7)
> at async buildOverridesEnabledResources (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/build-override-enabled-resources.js:31:3)
> at async Object.run (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/initialize-env.js:116:3)

### Expected behavior

It's obviously ok to fail the build in the Linux environment. However I would expect a more suitable error message in that case.
Can we fail the build if the provided rootPath to https://github.com/aws-amplify/amplify-cli/blob/5ea0b9a3787f68111a0a9492446383c60c8488a0/packages/amplify-cli-core/src/utils/packageManager.ts#L41

does not exist?

Something along the lines of

```javascript
if (rootPath && !fs.existsSync( rootPath )) {
throw new Error(`The provided rootPath ${rootPath} does not exist`)
}
```

### Reproduction steps

1. create a custom resource which has a directory name starting with upper case and a resource name with lower case (in backend-config.json)
2. run `amplify push` on macOS (or any other case insensitive file system, it will succeed
3. try to deploy via amplify hosting (or with any other case sensitive file system). The build will fail.

### GraphQL schema(s)

_No response_

### Project Identifier

_No response_

### Log output

```
# Put your logs below this line
2022-07-04T11:51:50.574Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 7.6.14 to 9.1.0...
2022-07-04T11:53:07.463Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 9.1.0
2022-07-04T11:53:07.539Z [INFO]: # Retrieving cache...
2022-07-04T11:53:07.580Z [INFO]: # Extracting cache...
2022-07-04T11:53:07.589Z [INFO]: # Extraction completed
2022-07-04T11:53:10.839Z [INFO]: ## Starting Backend Build
# Starting phase: build
2022-07-04T11:53:12.785Z [INFO]: Amplify AppID found: . Amplify App name is: 
2022-07-04T11:53:12.828Z [INFO]: Backend environment dev found in Amplify Console app: [0m
2022-07-04T11:53:13.597Z [WARNING]: - Fetching updates to backend environment: dev from the cloud.
2022-07-04T11:53:14.436Z [INFO]: Overrides functionality is not implemented for this category
2022-07-04T11:53:14.437Z [INFO]: Overrides functionality is not implemented for this category
Overrides functionality is not implemented for this category
2022-07-04T11:53:14.437Z [WARNING]: - Building resource storage/JpegImages
- Building resource auth/cognito88720486
- Building resource api/orderGraphQlAPI
- Building resource custom/lambdaTriggerIotEventsCollector
- Building custom resources
2022-07-04T11:53:14.464Z [INFO]: 🛑 There was an error building the custom resources
2022-07-04T11:53:14.465Z [INFO]: 🛑 Error: No package manager found. Please install npm or yarn to compile overrides for this project.
at buildResource (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:78:15)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async buildCustomResources (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:43:13)
at async transformCategoryStack (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/index.js:54:5)
at async transformResourceWithOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/override-manager/transform-resource.js:80:9)
at async Object.buildOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/utility-functions.js:106:7)
at async buildOverridesEnabledResources (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/build-override-enabled-resources.js:31:3)
at async Object.run (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/initialize-env.js:116:3)

```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in packages/amplify-cli-core/src/utils/packageManager.ts at the linked rootPath handling, then trace how custom resource builds call it. Reproduce the case-mismatched resource path from the issue on a case-sensitive filesystem. Done means a missing provided rootPath produces an explicit path-related error instead of the misleading package-manager message.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.