aws-amplify / aws-amplify/amplify-cli

`amplify publish` is not running build command correctly

Open
#11,115 2 comments 0 reactions 0 assignees View on GitHub
bug hosting 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 checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### App Id

dwx30wsa5jqse

### Region

ap-northeast-1

### Amplify Hosting feature

Build settings

### Describe the bug

My project directory structure is like
```
amplify
backend
frontend/
- build/
- node_modules/
- public/
- src/
- ...
- package.json
```

package.json (created by default by `npx create-react-app`)
```
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@aws-amplify/ui-react": "^3.2.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"aws-amplify": "^4.3.28",
"aws-amplify-react": "^5.1.9",
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
```

And I configured Amplify project like
```
? Which setting do you want to configure? Project information
? Enter a name for the project serverlesslaravelsam
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react
? Source Directory Path: frontend/src
? Distribution Directory Path: frontend/build
? Build Command: cd frontend && npm run build
? Start Command: cd frontend && npm run start
Using default provider awscloudformation
```

And I `amplify publish` and it doesn't build the frontend project, so that I need to manually run `npm run build` every time I want to publish frontend.

### Expected behavior

`amplify publish` automatically calls `npm run build`.

### Reproduction steps

* mkdir amplify-test
* cd amplify-test
* npx create-react-app frontend
* amplify init
* amplify add hosting
* amplify publish -y

### Build Settings

```yaml
Don't have one
```

### Additional information

I'm using `amplify add auth` and `amplify add hosting` for side note

Contributor guide

Open the contributing guide

Research direction

Start with the reported reproduction steps and the frontend/package.json build script, then trace how amplify publish reads the configured build command. Confirm whether cd frontend && npm run build is invoked during publishing; done means the command runs automatically and frontend/build is produced without a manual build.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, react, typescript
Domain
build-system, cli, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.