Skip to content

postinstall script fails when package is installed as a dependency - husky: command not found #205

Description

@Franklyn-luupli

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:

"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)

"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

"scripts": {
  "postinstall": "node -e \"try{require('husky')}catch(e){}\""
}

Option 3: Move to prepare script with better-sqlite3 pattern

"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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions