aws / aws/amazon-ivs-react-native-player
`postinstall` script fails when package is installed as a dependency - `husky: command not found`
- Dominant language
- TypeScript
- Stars
- 313
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
### Problem
The package fails to install as a dependency in downstream projects due to the `postinstall` script attempting to run `husky`, which is only available in `devDependencies`.
### Error
```
error /path/to/node_modules/amazon-ivs-react-native-player: Command failed.
Exit code: 127
Command: husky
Arguments:
Directory: /path/to/node_modules/amazon-ivs-react-native-player
Output:
```
Exit code 127 indicates "command not found" - when this package is installed as a dependency in another project, `husky` is not available because it's only listed in `devDependencies`.
### Root Cause
In `package.json`, there's a postinstall script:
```json
"scripts": {
"postinstall": "husky"
}
```
This script runs during `yarn install` or `npm install` for any project that depends on this package, but `husky` is only needed for contributors developing this package itself.
### Expected Behavior
The package should install successfully as a dependency without requiring dev tooling like `husky`.
### Steps to Reproduce
1. Create a new React Native project
2. Run `yarn add amazon-ivs-react-native-player@1.6.0`
3. Observe the postinstall script failure
### Suggested Fix
Husky's postinstall script should only run during development, not when the package is consumed as a dependency. Consider one of these approaches:
**Option 1: Remove postinstall entirely** (recommended for published packages)
```json
"scripts": {
"prepare": "husky"
}
```
The `prepare` script runs during `npm install` in the source directory but not when installed as a dependency.
**Option 2: Use conditional execution**
```json
"scripts": {
"postinstall": "node -e \"try{require('husky')}catch(e){}\""
}
```
**Option 3: Move to prepare script with better-sqlite3 pattern**
```json
"scripts": {
"prepare": "node -e \"try{require('husky')}catch(e){if(e.code!=='MODULE_NOT_FOUND')throw e}\""
}
```
### Environment
- Package version: 1.6.0
- Node version: (varies)
- Package manager: Yarn 3.x / npm
Contributor guide
Research direction
Start in package.json at the postinstall script and compare its behavior when the package is installed from its source versus as a dependency. Reproduce the failure with yarn or npm in a downstream React Native project; done means version 1.6.0 installs successfully without requiring husky as dependency tooling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100